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); |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 1711 | netif_carrier_on(card->dev); |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 1712 | qeth_schedule_recovery(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | return NULL; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1714 | case IPA_CMD_MODCCID: |
| 1715 | return cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | case IPA_CMD_REGISTER_LOCAL_ADDR: |
| 1717 | QETH_DBF_TEXT(trace,3, "irla"); |
| 1718 | break; |
| 1719 | case IPA_CMD_UNREGISTER_LOCAL_ADDR: |
| 1720 | QETH_DBF_TEXT(trace,3, "urla"); |
| 1721 | break; |
| 1722 | default: |
| 1723 | PRINT_WARN("Received data is IPA " |
| 1724 | "but not a reply!\n"); |
| 1725 | break; |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | return cmd; |
| 1730 | } |
| 1731 | |
| 1732 | /** |
| 1733 | * wake all waiting ipa commands |
| 1734 | */ |
| 1735 | static void |
| 1736 | qeth_clear_ipacmd_list(struct qeth_card *card) |
| 1737 | { |
| 1738 | struct qeth_reply *reply, *r; |
| 1739 | unsigned long flags; |
| 1740 | |
| 1741 | QETH_DBF_TEXT(trace, 4, "clipalst"); |
| 1742 | |
| 1743 | spin_lock_irqsave(&card->lock, flags); |
| 1744 | list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { |
| 1745 | qeth_get_reply(reply); |
| 1746 | reply->rc = -EIO; |
| 1747 | reply->received = 1; |
| 1748 | list_del_init(&reply->list); |
| 1749 | wake_up(&reply->wait_q); |
| 1750 | qeth_put_reply(reply); |
| 1751 | } |
| 1752 | spin_unlock_irqrestore(&card->lock, flags); |
| 1753 | } |
| 1754 | |
| 1755 | static void |
| 1756 | qeth_send_control_data_cb(struct qeth_channel *channel, |
| 1757 | struct qeth_cmd_buffer *iob) |
| 1758 | { |
| 1759 | struct qeth_card *card; |
| 1760 | struct qeth_reply *reply, *r; |
| 1761 | struct qeth_ipa_cmd *cmd; |
| 1762 | unsigned long flags; |
| 1763 | int keep_reply; |
| 1764 | |
| 1765 | QETH_DBF_TEXT(trace,4,"sndctlcb"); |
| 1766 | |
| 1767 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 1768 | if (qeth_check_idx_response(iob->data)) { |
| 1769 | qeth_clear_ipacmd_list(card); |
| 1770 | qeth_schedule_recovery(card); |
| 1771 | goto out; |
| 1772 | } |
| 1773 | |
| 1774 | cmd = qeth_check_ipa_data(card, iob); |
| 1775 | if ((cmd == NULL) && (card->state != CARD_STATE_DOWN)) |
| 1776 | goto out; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1777 | /*in case of OSN : check if cmd is set */ |
| 1778 | if (card->info.type == QETH_CARD_TYPE_OSN && |
| 1779 | cmd && |
| 1780 | cmd->hdr.command != IPA_CMD_STARTLAN && |
| 1781 | card->osn_info.assist_cb != NULL) { |
| 1782 | card->osn_info.assist_cb(card->dev, cmd); |
| 1783 | goto out; |
| 1784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
| 1786 | spin_lock_irqsave(&card->lock, flags); |
| 1787 | list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { |
| 1788 | if ((reply->seqno == QETH_IDX_COMMAND_SEQNO) || |
| 1789 | ((cmd) && (reply->seqno == cmd->hdr.seqno))) { |
| 1790 | qeth_get_reply(reply); |
| 1791 | list_del_init(&reply->list); |
| 1792 | spin_unlock_irqrestore(&card->lock, flags); |
| 1793 | keep_reply = 0; |
| 1794 | if (reply->callback != NULL) { |
| 1795 | if (cmd) { |
| 1796 | reply->offset = (__u16)((char*)cmd - |
| 1797 | (char *)iob->data); |
| 1798 | keep_reply = reply->callback(card, |
| 1799 | reply, |
| 1800 | (unsigned long)cmd); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1801 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | keep_reply = reply->callback(card, |
| 1803 | reply, |
| 1804 | (unsigned long)iob); |
| 1805 | } |
| 1806 | if (cmd) |
| 1807 | reply->rc = (u16) cmd->hdr.return_code; |
| 1808 | else if (iob->rc) |
| 1809 | reply->rc = iob->rc; |
| 1810 | if (keep_reply) { |
| 1811 | spin_lock_irqsave(&card->lock, flags); |
| 1812 | list_add_tail(&reply->list, |
| 1813 | &card->cmd_waiter_list); |
| 1814 | spin_unlock_irqrestore(&card->lock, flags); |
| 1815 | } else { |
| 1816 | reply->received = 1; |
| 1817 | wake_up(&reply->wait_q); |
| 1818 | } |
| 1819 | qeth_put_reply(reply); |
| 1820 | goto out; |
| 1821 | } |
| 1822 | } |
| 1823 | spin_unlock_irqrestore(&card->lock, flags); |
| 1824 | out: |
| 1825 | memcpy(&card->seqno.pdu_hdr_ack, |
| 1826 | QETH_PDU_HEADER_SEQ_NO(iob->data), |
| 1827 | QETH_SEQ_NO_LENGTH); |
| 1828 | qeth_release_buffer(channel,iob); |
| 1829 | } |
| 1830 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1831 | static inline void |
| 1832 | qeth_prepare_control_data(struct qeth_card *card, int len, |
| 1833 | struct qeth_cmd_buffer *iob) |
| 1834 | { |
| 1835 | qeth_setup_ccw(&card->write,iob->data,len); |
| 1836 | iob->callback = qeth_release_buffer; |
| 1837 | |
| 1838 | memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data), |
| 1839 | &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH); |
| 1840 | card->seqno.trans_hdr++; |
| 1841 | memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data), |
| 1842 | &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH); |
| 1843 | card->seqno.pdu_hdr++; |
| 1844 | memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data), |
| 1845 | &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH); |
| 1846 | QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); |
| 1847 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | static int |
| 1850 | qeth_send_control_data(struct qeth_card *card, int len, |
| 1851 | struct qeth_cmd_buffer *iob, |
| 1852 | int (*reply_cb) |
| 1853 | (struct qeth_card *, struct qeth_reply*, unsigned long), |
| 1854 | void *reply_param) |
| 1855 | |
| 1856 | { |
| 1857 | int rc; |
| 1858 | unsigned long flags; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1859 | struct qeth_reply *reply = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | struct timer_list timer; |
| 1861 | |
| 1862 | QETH_DBF_TEXT(trace, 2, "sendctl"); |
| 1863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | reply = qeth_alloc_reply(card); |
| 1865 | if (!reply) { |
| 1866 | PRINT_WARN("Could no alloc qeth_reply!\n"); |
| 1867 | return -ENOMEM; |
| 1868 | } |
| 1869 | reply->callback = reply_cb; |
| 1870 | reply->param = reply_param; |
| 1871 | if (card->state == CARD_STATE_DOWN) |
| 1872 | reply->seqno = QETH_IDX_COMMAND_SEQNO; |
| 1873 | else |
| 1874 | reply->seqno = card->seqno.ipa++; |
| 1875 | init_timer(&timer); |
| 1876 | timer.function = qeth_cmd_timeout; |
| 1877 | timer.data = (unsigned long) reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | init_waitqueue_head(&reply->wait_q); |
| 1879 | spin_lock_irqsave(&card->lock, flags); |
| 1880 | list_add_tail(&reply->list, &card->cmd_waiter_list); |
| 1881 | spin_unlock_irqrestore(&card->lock, flags); |
| 1882 | QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); |
| 1883 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1884 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1885 | qeth_prepare_control_data(card, len, iob); |
| 1886 | if (IS_IPA(iob->data)) |
| 1887 | timer.expires = jiffies + QETH_IPA_TIMEOUT; |
| 1888 | else |
| 1889 | timer.expires = jiffies + QETH_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | QETH_DBF_TEXT(trace, 6, "noirqpnd"); |
| 1891 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1892 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1893 | (addr_t) iob, 0, 0); |
| 1894 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1895 | if (rc){ |
| 1896 | PRINT_WARN("qeth_send_control_data: " |
| 1897 | "ccw_device_start rc = %i\n", rc); |
| 1898 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
| 1899 | spin_lock_irqsave(&card->lock, flags); |
| 1900 | list_del_init(&reply->list); |
| 1901 | qeth_put_reply(reply); |
| 1902 | spin_unlock_irqrestore(&card->lock, flags); |
| 1903 | qeth_release_buffer(iob->channel, iob); |
| 1904 | atomic_set(&card->write.irq_pending, 0); |
| 1905 | wake_up(&card->wait_q); |
| 1906 | return rc; |
| 1907 | } |
| 1908 | add_timer(&timer); |
| 1909 | wait_event(reply->wait_q, reply->received); |
| 1910 | del_timer_sync(&timer); |
| 1911 | rc = reply->rc; |
| 1912 | qeth_put_reply(reply); |
| 1913 | return rc; |
| 1914 | } |
| 1915 | |
| 1916 | static int |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1917 | qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1918 | struct qeth_cmd_buffer *iob) |
| 1919 | { |
| 1920 | unsigned long flags; |
| 1921 | int rc = 0; |
| 1922 | |
| 1923 | QETH_DBF_TEXT(trace, 5, "osndctrd"); |
| 1924 | |
| 1925 | wait_event(card->wait_q, |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 1926 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1927 | qeth_prepare_control_data(card, len, iob); |
| 1928 | QETH_DBF_TEXT(trace, 6, "osnoirqp"); |
| 1929 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1930 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1931 | (addr_t) iob, 0, 0); |
| 1932 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1933 | if (rc){ |
| 1934 | PRINT_WARN("qeth_osn_send_control_data: " |
| 1935 | "ccw_device_start rc = %i\n", rc); |
| 1936 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
| 1937 | qeth_release_buffer(iob->channel, iob); |
| 1938 | atomic_set(&card->write.irq_pending, 0); |
| 1939 | wake_up(&card->wait_q); |
| 1940 | } |
| 1941 | return rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1942 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1943 | |
| 1944 | static inline void |
| 1945 | qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1946 | char prot_type) |
| 1947 | { |
| 1948 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 1949 | memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1); |
| 1950 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 1951 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 1952 | } |
| 1953 | |
| 1954 | static int |
| 1955 | qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1956 | int data_len) |
| 1957 | { |
| 1958 | u16 s1, s2; |
| 1959 | |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 1960 | QETH_DBF_TEXT(trace,4,"osndipa"); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1961 | |
| 1962 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1963 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1964 | s2 = (u16)data_len; |
| 1965 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1966 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1967 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1968 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1969 | return qeth_osn_send_control_data(card, s1, iob); |
| 1970 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1971 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1972 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 1974 | int (*reply_cb) |
| 1975 | (struct qeth_card *,struct qeth_reply*, unsigned long), |
| 1976 | void *reply_param) |
| 1977 | { |
| 1978 | int rc; |
| 1979 | char prot_type; |
| 1980 | |
| 1981 | QETH_DBF_TEXT(trace,4,"sendipa"); |
| 1982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1984 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 1985 | prot_type = QETH_PROT_OSN2; |
| 1986 | else |
| 1987 | prot_type = QETH_PROT_LAYER2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | else |
| 1989 | prot_type = QETH_PROT_TCPIP; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 1990 | qeth_prepare_ipa_cmd(card,iob,prot_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob, |
| 1992 | reply_cb, reply_param); |
| 1993 | return rc; |
| 1994 | } |
| 1995 | |
| 1996 | |
| 1997 | static int |
| 1998 | qeth_cm_enable_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 1999 | unsigned long data) |
| 2000 | { |
| 2001 | struct qeth_cmd_buffer *iob; |
| 2002 | |
| 2003 | QETH_DBF_TEXT(setup, 2, "cmenblcb"); |
| 2004 | |
| 2005 | iob = (struct qeth_cmd_buffer *) data; |
| 2006 | memcpy(&card->token.cm_filter_r, |
| 2007 | QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob->data), |
| 2008 | QETH_MPC_TOKEN_LENGTH); |
| 2009 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2010 | return 0; |
| 2011 | } |
| 2012 | |
| 2013 | static int |
| 2014 | qeth_cm_enable(struct qeth_card *card) |
| 2015 | { |
| 2016 | int rc; |
| 2017 | struct qeth_cmd_buffer *iob; |
| 2018 | |
| 2019 | QETH_DBF_TEXT(setup,2,"cmenable"); |
| 2020 | |
| 2021 | iob = qeth_wait_for_buffer(&card->write); |
| 2022 | memcpy(iob->data, CM_ENABLE, CM_ENABLE_SIZE); |
| 2023 | memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob->data), |
| 2024 | &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH); |
| 2025 | memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob->data), |
| 2026 | &card->token.cm_filter_w, QETH_MPC_TOKEN_LENGTH); |
| 2027 | |
| 2028 | rc = qeth_send_control_data(card, CM_ENABLE_SIZE, iob, |
| 2029 | qeth_cm_enable_cb, NULL); |
| 2030 | return rc; |
| 2031 | } |
| 2032 | |
| 2033 | static int |
| 2034 | qeth_cm_setup_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2035 | unsigned long data) |
| 2036 | { |
| 2037 | |
| 2038 | struct qeth_cmd_buffer *iob; |
| 2039 | |
| 2040 | QETH_DBF_TEXT(setup, 2, "cmsetpcb"); |
| 2041 | |
| 2042 | iob = (struct qeth_cmd_buffer *) data; |
| 2043 | memcpy(&card->token.cm_connection_r, |
| 2044 | QETH_CM_SETUP_RESP_DEST_ADDR(iob->data), |
| 2045 | QETH_MPC_TOKEN_LENGTH); |
| 2046 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | static int |
| 2051 | qeth_cm_setup(struct qeth_card *card) |
| 2052 | { |
| 2053 | int rc; |
| 2054 | struct qeth_cmd_buffer *iob; |
| 2055 | |
| 2056 | QETH_DBF_TEXT(setup,2,"cmsetup"); |
| 2057 | |
| 2058 | iob = qeth_wait_for_buffer(&card->write); |
| 2059 | memcpy(iob->data, CM_SETUP, CM_SETUP_SIZE); |
| 2060 | memcpy(QETH_CM_SETUP_DEST_ADDR(iob->data), |
| 2061 | &card->token.issuer_rm_r, QETH_MPC_TOKEN_LENGTH); |
| 2062 | memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob->data), |
| 2063 | &card->token.cm_connection_w, QETH_MPC_TOKEN_LENGTH); |
| 2064 | memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob->data), |
| 2065 | &card->token.cm_filter_r, QETH_MPC_TOKEN_LENGTH); |
| 2066 | rc = qeth_send_control_data(card, CM_SETUP_SIZE, iob, |
| 2067 | qeth_cm_setup_cb, NULL); |
| 2068 | return rc; |
| 2069 | |
| 2070 | } |
| 2071 | |
| 2072 | static int |
| 2073 | qeth_ulp_enable_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2074 | unsigned long data) |
| 2075 | { |
| 2076 | |
| 2077 | __u16 mtu, framesize; |
| 2078 | __u16 len; |
| 2079 | __u8 link_type; |
| 2080 | struct qeth_cmd_buffer *iob; |
| 2081 | |
| 2082 | QETH_DBF_TEXT(setup, 2, "ulpenacb"); |
| 2083 | |
| 2084 | iob = (struct qeth_cmd_buffer *) data; |
| 2085 | memcpy(&card->token.ulp_filter_r, |
| 2086 | QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob->data), |
| 2087 | QETH_MPC_TOKEN_LENGTH); |
| 2088 | if (qeth_get_mtu_out_of_mpc(card->info.type)) { |
| 2089 | memcpy(&framesize, QETH_ULP_ENABLE_RESP_MAX_MTU(iob->data), 2); |
| 2090 | mtu = qeth_get_mtu_outof_framesize(framesize); |
| 2091 | if (!mtu) { |
| 2092 | iob->rc = -EINVAL; |
| 2093 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2094 | return 0; |
| 2095 | } |
| 2096 | card->info.max_mtu = mtu; |
| 2097 | card->info.initial_mtu = mtu; |
| 2098 | card->qdio.in_buf_size = mtu + 2 * PAGE_SIZE; |
| 2099 | } else { |
| 2100 | card->info.initial_mtu = qeth_get_initial_mtu_for_card(card); |
| 2101 | card->info.max_mtu = qeth_get_max_mtu_for_card(card->info.type); |
| 2102 | card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT; |
| 2103 | } |
| 2104 | |
| 2105 | memcpy(&len, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob->data), 2); |
| 2106 | if (len >= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE) { |
| 2107 | memcpy(&link_type, |
| 2108 | QETH_ULP_ENABLE_RESP_LINK_TYPE(iob->data), 1); |
| 2109 | card->info.link_type = link_type; |
| 2110 | } else |
| 2111 | card->info.link_type = 0; |
| 2112 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2113 | return 0; |
| 2114 | } |
| 2115 | |
| 2116 | static int |
| 2117 | qeth_ulp_enable(struct qeth_card *card) |
| 2118 | { |
| 2119 | int rc; |
| 2120 | char prot_type; |
| 2121 | struct qeth_cmd_buffer *iob; |
| 2122 | |
| 2123 | /*FIXME: trace view callbacks*/ |
| 2124 | QETH_DBF_TEXT(setup,2,"ulpenabl"); |
| 2125 | |
| 2126 | iob = qeth_wait_for_buffer(&card->write); |
| 2127 | memcpy(iob->data, ULP_ENABLE, ULP_ENABLE_SIZE); |
| 2128 | |
| 2129 | *(QETH_ULP_ENABLE_LINKNUM(iob->data)) = |
| 2130 | (__u8) card->info.portno; |
| 2131 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2132 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2133 | prot_type = QETH_PROT_OSN2; |
| 2134 | else |
| 2135 | prot_type = QETH_PROT_LAYER2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | else |
| 2137 | prot_type = QETH_PROT_TCPIP; |
| 2138 | |
| 2139 | memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob->data),&prot_type,1); |
| 2140 | memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob->data), |
| 2141 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 2142 | memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob->data), |
| 2143 | &card->token.ulp_filter_w, QETH_MPC_TOKEN_LENGTH); |
| 2144 | memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob->data), |
| 2145 | card->info.portname, 9); |
| 2146 | rc = qeth_send_control_data(card, ULP_ENABLE_SIZE, iob, |
| 2147 | qeth_ulp_enable_cb, NULL); |
| 2148 | return rc; |
| 2149 | |
| 2150 | } |
| 2151 | |
| 2152 | static inline __u16 |
| 2153 | __raw_devno_from_bus_id(char *id) |
| 2154 | { |
| 2155 | id += (strlen(id) - 4); |
| 2156 | return (__u16) simple_strtoul(id, &id, 16); |
| 2157 | } |
| 2158 | |
| 2159 | static int |
| 2160 | qeth_ulp_setup_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 2161 | unsigned long data) |
| 2162 | { |
| 2163 | struct qeth_cmd_buffer *iob; |
| 2164 | |
| 2165 | QETH_DBF_TEXT(setup, 2, "ulpstpcb"); |
| 2166 | |
| 2167 | iob = (struct qeth_cmd_buffer *) data; |
| 2168 | memcpy(&card->token.ulp_connection_r, |
| 2169 | QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob->data), |
| 2170 | QETH_MPC_TOKEN_LENGTH); |
| 2171 | QETH_DBF_TEXT_(setup, 2, " rc%d", iob->rc); |
| 2172 | return 0; |
| 2173 | } |
| 2174 | |
| 2175 | static int |
| 2176 | qeth_ulp_setup(struct qeth_card *card) |
| 2177 | { |
| 2178 | int rc; |
| 2179 | __u16 temp; |
| 2180 | struct qeth_cmd_buffer *iob; |
| 2181 | |
| 2182 | QETH_DBF_TEXT(setup,2,"ulpsetup"); |
| 2183 | |
| 2184 | iob = qeth_wait_for_buffer(&card->write); |
| 2185 | memcpy(iob->data, ULP_SETUP, ULP_SETUP_SIZE); |
| 2186 | |
| 2187 | memcpy(QETH_ULP_SETUP_DEST_ADDR(iob->data), |
| 2188 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 2189 | memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob->data), |
| 2190 | &card->token.ulp_connection_w, QETH_MPC_TOKEN_LENGTH); |
| 2191 | memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob->data), |
| 2192 | &card->token.ulp_filter_r, QETH_MPC_TOKEN_LENGTH); |
| 2193 | |
| 2194 | temp = __raw_devno_from_bus_id(CARD_DDEV_ID(card)); |
| 2195 | memcpy(QETH_ULP_SETUP_CUA(iob->data), &temp, 2); |
| 2196 | temp = (card->info.cula << 8) + card->info.unit_addr2; |
| 2197 | memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob->data), &temp, 2); |
| 2198 | rc = qeth_send_control_data(card, ULP_SETUP_SIZE, iob, |
| 2199 | qeth_ulp_setup_cb, NULL); |
| 2200 | return rc; |
| 2201 | } |
| 2202 | |
| 2203 | static inline int |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2204 | qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error, |
| 2205 | unsigned int siga_error, const char *dbftext) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | if (qdio_error || siga_error) { |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2208 | QETH_DBF_TEXT(trace, 2, dbftext); |
| 2209 | QETH_DBF_TEXT(qerr, 2, dbftext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | QETH_DBF_TEXT_(qerr, 2, " F15=%02X", |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2211 | buf->element[15].flags & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | QETH_DBF_TEXT_(qerr, 2, " F14=%02X", |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2213 | buf->element[14].flags & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | QETH_DBF_TEXT_(qerr, 2, " qerr=%X", qdio_error); |
| 2215 | QETH_DBF_TEXT_(qerr, 2, " serr=%X", siga_error); |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2216 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | } |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2218 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | static inline struct sk_buff * |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2222 | qeth_get_skb(unsigned int length, struct qeth_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | { |
| 2224 | struct sk_buff* skb; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2225 | int add_len; |
| 2226 | |
| 2227 | add_len = 0; |
| 2228 | if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN) |
| 2229 | add_len = sizeof(struct qeth_hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | #ifdef CONFIG_QETH_VLAN |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2231 | else |
| 2232 | add_len = VLAN_HLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2234 | skb = dev_alloc_skb(length + add_len); |
| 2235 | if (skb && add_len) |
| 2236 | skb_reserve(skb, add_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | return skb; |
| 2238 | } |
| 2239 | |
| 2240 | static inline struct sk_buff * |
| 2241 | qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer, |
| 2242 | struct qdio_buffer_element **__element, int *__offset, |
| 2243 | struct qeth_hdr **hdr) |
| 2244 | { |
| 2245 | struct qdio_buffer_element *element = *__element; |
| 2246 | int offset = *__offset; |
| 2247 | struct sk_buff *skb = NULL; |
| 2248 | int skb_len; |
| 2249 | void *data_ptr; |
| 2250 | int data_len; |
| 2251 | |
| 2252 | QETH_DBF_TEXT(trace,6,"nextskb"); |
| 2253 | /* qeth_hdr must not cross element boundaries */ |
| 2254 | if (element->length < offset + sizeof(struct qeth_hdr)){ |
| 2255 | if (qeth_is_last_sbale(element)) |
| 2256 | return NULL; |
| 2257 | element++; |
| 2258 | offset = 0; |
| 2259 | if (element->length < sizeof(struct qeth_hdr)) |
| 2260 | return NULL; |
| 2261 | } |
| 2262 | *hdr = element->addr + offset; |
| 2263 | |
| 2264 | offset += sizeof(struct qeth_hdr); |
| 2265 | if (card->options.layer2) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2266 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2267 | skb_len = (*hdr)->hdr.osn.pdu_length; |
| 2268 | else |
| 2269 | skb_len = (*hdr)->hdr.l2.pkt_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | else |
| 2271 | skb_len = (*hdr)->hdr.l3.length; |
| 2272 | |
| 2273 | if (!skb_len) |
| 2274 | return NULL; |
| 2275 | if (card->options.fake_ll){ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2276 | if(card->dev->type == ARPHRD_IEEE802_TR){ |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2277 | 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] | 2278 | goto no_mem; |
| 2279 | skb_reserve(skb,QETH_FAKE_LL_LEN_TR); |
| 2280 | } else { |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2281 | 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] | 2282 | goto no_mem; |
| 2283 | skb_reserve(skb,QETH_FAKE_LL_LEN_ETH); |
| 2284 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2285 | } else if (!(skb = qeth_get_skb(skb_len, *hdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | goto no_mem; |
| 2287 | data_ptr = element->addr + offset; |
| 2288 | while (skb_len) { |
| 2289 | data_len = min(skb_len, (int)(element->length - offset)); |
| 2290 | if (data_len) |
| 2291 | memcpy(skb_put(skb, data_len), data_ptr, data_len); |
| 2292 | skb_len -= data_len; |
| 2293 | if (skb_len){ |
| 2294 | if (qeth_is_last_sbale(element)){ |
| 2295 | QETH_DBF_TEXT(trace,4,"unexeob"); |
| 2296 | QETH_DBF_TEXT_(trace,4,"%s",CARD_BUS_ID(card)); |
| 2297 | QETH_DBF_TEXT(qerr,2,"unexeob"); |
| 2298 | QETH_DBF_TEXT_(qerr,2,"%s",CARD_BUS_ID(card)); |
| 2299 | QETH_DBF_HEX(misc,4,buffer,sizeof(*buffer)); |
| 2300 | dev_kfree_skb_any(skb); |
| 2301 | card->stats.rx_errors++; |
| 2302 | return NULL; |
| 2303 | } |
| 2304 | element++; |
| 2305 | offset = 0; |
| 2306 | data_ptr = element->addr; |
| 2307 | } else { |
| 2308 | offset += data_len; |
| 2309 | } |
| 2310 | } |
| 2311 | *__element = element; |
| 2312 | *__offset = offset; |
| 2313 | return skb; |
| 2314 | no_mem: |
| 2315 | if (net_ratelimit()){ |
| 2316 | PRINT_WARN("No memory for packet received on %s.\n", |
| 2317 | QETH_CARD_IFNAME(card)); |
| 2318 | QETH_DBF_TEXT(trace,2,"noskbmem"); |
| 2319 | QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card)); |
| 2320 | } |
| 2321 | card->stats.rx_dropped++; |
| 2322 | return NULL; |
| 2323 | } |
| 2324 | |
Alexey Dobriyan | ab61148 | 2005-07-12 12:08:43 -0700 | [diff] [blame] | 2325 | static inline __be16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | qeth_type_trans(struct sk_buff *skb, struct net_device *dev) |
| 2327 | { |
| 2328 | struct qeth_card *card; |
| 2329 | struct ethhdr *eth; |
| 2330 | |
| 2331 | QETH_DBF_TEXT(trace,6,"typtrans"); |
| 2332 | |
| 2333 | card = (struct qeth_card *)dev->priv; |
| 2334 | #ifdef CONFIG_TR |
| 2335 | if ((card->info.link_type == QETH_LINK_TYPE_HSTR) || |
| 2336 | (card->info.link_type == QETH_LINK_TYPE_LANE_TR)) |
| 2337 | return tr_type_trans(skb,dev); |
| 2338 | #endif /* CONFIG_TR */ |
| 2339 | skb->mac.raw = skb->data; |
| 2340 | skb_pull(skb, ETH_HLEN ); |
| 2341 | eth = eth_hdr(skb); |
| 2342 | |
| 2343 | if (*eth->h_dest & 1) { |
| 2344 | if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0) |
| 2345 | skb->pkt_type = PACKET_BROADCAST; |
| 2346 | else |
| 2347 | skb->pkt_type = PACKET_MULTICAST; |
| 2348 | } else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN)) |
| 2349 | skb->pkt_type = PACKET_OTHERHOST; |
| 2350 | |
| 2351 | if (ntohs(eth->h_proto) >= 1536) |
| 2352 | return eth->h_proto; |
| 2353 | if (*(unsigned short *) (skb->data) == 0xFFFF) |
| 2354 | return htons(ETH_P_802_3); |
| 2355 | return htons(ETH_P_802_2); |
| 2356 | } |
| 2357 | |
| 2358 | static inline void |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2359 | qeth_rebuild_skb_fake_ll_tr(struct qeth_card *card, struct sk_buff *skb, |
| 2360 | struct qeth_hdr *hdr) |
| 2361 | { |
| 2362 | struct trh_hdr *fake_hdr; |
| 2363 | struct trllc *fake_llc; |
| 2364 | struct iphdr *ip_hdr; |
| 2365 | |
| 2366 | QETH_DBF_TEXT(trace,5,"skbfktr"); |
| 2367 | skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_TR; |
| 2368 | /* this is a fake ethernet header */ |
| 2369 | fake_hdr = (struct trh_hdr *) skb->mac.raw; |
| 2370 | |
| 2371 | /* the destination MAC address */ |
| 2372 | switch (skb->pkt_type){ |
| 2373 | case PACKET_MULTICAST: |
| 2374 | switch (skb->protocol){ |
| 2375 | #ifdef CONFIG_QETH_IPV6 |
| 2376 | case __constant_htons(ETH_P_IPV6): |
| 2377 | ndisc_mc_map((struct in6_addr *) |
| 2378 | skb->data + QETH_FAKE_LL_V6_ADDR_POS, |
| 2379 | fake_hdr->daddr, card->dev, 0); |
| 2380 | break; |
| 2381 | #endif /* CONFIG_QETH_IPV6 */ |
| 2382 | case __constant_htons(ETH_P_IP): |
| 2383 | ip_hdr = (struct iphdr *)skb->data; |
| 2384 | ip_tr_mc_map(ip_hdr->daddr, fake_hdr->daddr); |
| 2385 | break; |
| 2386 | default: |
| 2387 | memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN); |
| 2388 | } |
| 2389 | break; |
| 2390 | case PACKET_BROADCAST: |
| 2391 | memset(fake_hdr->daddr, 0xff, TR_ALEN); |
| 2392 | break; |
| 2393 | default: |
| 2394 | memcpy(fake_hdr->daddr, card->dev->dev_addr, TR_ALEN); |
| 2395 | } |
| 2396 | /* the source MAC address */ |
| 2397 | if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) |
| 2398 | memcpy(fake_hdr->saddr, &hdr->hdr.l3.dest_addr[2], TR_ALEN); |
| 2399 | else |
| 2400 | memset(fake_hdr->saddr, 0, TR_ALEN); |
| 2401 | fake_hdr->rcf=0; |
| 2402 | fake_llc = (struct trllc*)&(fake_hdr->rcf); |
| 2403 | fake_llc->dsap = EXTENDED_SAP; |
| 2404 | fake_llc->ssap = EXTENDED_SAP; |
| 2405 | fake_llc->llc = UI_CMD; |
| 2406 | fake_llc->protid[0] = 0; |
| 2407 | fake_llc->protid[1] = 0; |
| 2408 | fake_llc->protid[2] = 0; |
| 2409 | fake_llc->ethertype = ETH_P_IP; |
| 2410 | } |
| 2411 | |
| 2412 | static inline void |
| 2413 | 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] | 2414 | struct qeth_hdr *hdr) |
| 2415 | { |
| 2416 | struct ethhdr *fake_hdr; |
| 2417 | struct iphdr *ip_hdr; |
| 2418 | |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2419 | QETH_DBF_TEXT(trace,5,"skbfketh"); |
| 2420 | skb->mac.raw = skb->data - QETH_FAKE_LL_LEN_ETH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | /* this is a fake ethernet header */ |
| 2422 | fake_hdr = (struct ethhdr *) skb->mac.raw; |
| 2423 | |
| 2424 | /* the destination MAC address */ |
| 2425 | switch (skb->pkt_type){ |
| 2426 | case PACKET_MULTICAST: |
| 2427 | switch (skb->protocol){ |
| 2428 | #ifdef CONFIG_QETH_IPV6 |
| 2429 | case __constant_htons(ETH_P_IPV6): |
| 2430 | ndisc_mc_map((struct in6_addr *) |
| 2431 | skb->data + QETH_FAKE_LL_V6_ADDR_POS, |
| 2432 | fake_hdr->h_dest, card->dev, 0); |
| 2433 | break; |
| 2434 | #endif /* CONFIG_QETH_IPV6 */ |
| 2435 | case __constant_htons(ETH_P_IP): |
| 2436 | ip_hdr = (struct iphdr *)skb->data; |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2437 | ip_eth_mc_map(ip_hdr->daddr, fake_hdr->h_dest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | break; |
| 2439 | default: |
| 2440 | memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN); |
| 2441 | } |
| 2442 | break; |
| 2443 | case PACKET_BROADCAST: |
| 2444 | memset(fake_hdr->h_dest, 0xff, ETH_ALEN); |
| 2445 | break; |
| 2446 | default: |
| 2447 | memcpy(fake_hdr->h_dest, card->dev->dev_addr, ETH_ALEN); |
| 2448 | } |
| 2449 | /* the source MAC address */ |
| 2450 | if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) |
| 2451 | memcpy(fake_hdr->h_source, &hdr->hdr.l3.dest_addr[2], ETH_ALEN); |
| 2452 | else |
| 2453 | memset(fake_hdr->h_source, 0, ETH_ALEN); |
| 2454 | /* the protocol */ |
| 2455 | fake_hdr->h_proto = skb->protocol; |
| 2456 | } |
| 2457 | |
| 2458 | static inline void |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 2459 | qeth_rebuild_skb_fake_ll(struct qeth_card *card, struct sk_buff *skb, |
| 2460 | struct qeth_hdr *hdr) |
| 2461 | { |
| 2462 | if (card->dev->type == ARPHRD_IEEE802_TR) |
| 2463 | qeth_rebuild_skb_fake_ll_tr(card, skb, hdr); |
| 2464 | else |
| 2465 | qeth_rebuild_skb_fake_ll_eth(card, skb, hdr); |
| 2466 | } |
| 2467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | static inline __u16 |
| 2469 | qeth_layer2_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, |
| 2470 | struct qeth_hdr *hdr) |
| 2471 | { |
| 2472 | unsigned short vlan_id = 0; |
| 2473 | #ifdef CONFIG_QETH_VLAN |
| 2474 | struct vlan_hdr *vhdr; |
| 2475 | #endif |
| 2476 | |
| 2477 | skb->pkt_type = PACKET_HOST; |
| 2478 | skb->protocol = qeth_type_trans(skb, skb->dev); |
| 2479 | if (card->options.checksum_type == NO_CHECKSUMMING) |
| 2480 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2481 | else |
| 2482 | skb->ip_summed = CHECKSUM_NONE; |
| 2483 | #ifdef CONFIG_QETH_VLAN |
| 2484 | if (hdr->hdr.l2.flags[2] & (QETH_LAYER2_FLAG_VLAN)) { |
| 2485 | vhdr = (struct vlan_hdr *) skb->data; |
| 2486 | skb->protocol = |
| 2487 | __constant_htons(vhdr->h_vlan_encapsulated_proto); |
| 2488 | vlan_id = hdr->hdr.l2.vlan_id; |
| 2489 | skb_pull(skb, VLAN_HLEN); |
| 2490 | } |
| 2491 | #endif |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 2492 | *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | return vlan_id; |
| 2494 | } |
| 2495 | |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2496 | static inline __u16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | qeth_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, |
| 2498 | struct qeth_hdr *hdr) |
| 2499 | { |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2500 | unsigned short vlan_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | #ifdef CONFIG_QETH_IPV6 |
| 2502 | if (hdr->hdr.l3.flags & QETH_HDR_PASSTHRU) { |
| 2503 | skb->pkt_type = PACKET_HOST; |
| 2504 | skb->protocol = qeth_type_trans(skb, card->dev); |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2505 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | } |
| 2507 | #endif /* CONFIG_QETH_IPV6 */ |
| 2508 | skb->protocol = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 : |
| 2509 | ETH_P_IP); |
| 2510 | switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK){ |
| 2511 | case QETH_CAST_UNICAST: |
| 2512 | skb->pkt_type = PACKET_HOST; |
| 2513 | break; |
| 2514 | case QETH_CAST_MULTICAST: |
| 2515 | skb->pkt_type = PACKET_MULTICAST; |
| 2516 | card->stats.multicast++; |
| 2517 | break; |
| 2518 | case QETH_CAST_BROADCAST: |
| 2519 | skb->pkt_type = PACKET_BROADCAST; |
| 2520 | card->stats.multicast++; |
| 2521 | break; |
| 2522 | case QETH_CAST_ANYCAST: |
| 2523 | case QETH_CAST_NOCAST: |
| 2524 | default: |
| 2525 | skb->pkt_type = PACKET_HOST; |
| 2526 | } |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2527 | |
| 2528 | if (hdr->hdr.l3.ext_flags & |
| 2529 | (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) { |
| 2530 | vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)? |
| 2531 | hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]); |
| 2532 | } |
| 2533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | if (card->options.fake_ll) |
| 2535 | qeth_rebuild_skb_fake_ll(card, skb, hdr); |
| 2536 | else |
| 2537 | skb->mac.raw = skb->data; |
| 2538 | skb->ip_summed = card->options.checksum_type; |
| 2539 | if (card->options.checksum_type == HW_CHECKSUMMING){ |
| 2540 | if ( (hdr->hdr.l3.ext_flags & |
| 2541 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 2542 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) == |
| 2543 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 2544 | QETH_HDR_EXT_CSUM_TRANSP_REQ) ) |
| 2545 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2546 | else |
| 2547 | skb->ip_summed = SW_CHECKSUMMING; |
| 2548 | } |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2549 | return vlan_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static inline void |
| 2553 | qeth_process_inbound_buffer(struct qeth_card *card, |
| 2554 | struct qeth_qdio_buffer *buf, int index) |
| 2555 | { |
| 2556 | struct qdio_buffer_element *element; |
| 2557 | struct sk_buff *skb; |
| 2558 | struct qeth_hdr *hdr; |
| 2559 | int offset; |
| 2560 | int rxrc; |
| 2561 | __u16 vlan_tag = 0; |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2562 | __u16 *vlan_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | |
| 2564 | /* get first element of current buffer */ |
| 2565 | element = (struct qdio_buffer_element *)&buf->buffer->element[0]; |
| 2566 | offset = 0; |
| 2567 | #ifdef CONFIG_QETH_PERF_STATS |
| 2568 | card->perf_stats.bufs_rec++; |
| 2569 | #endif |
| 2570 | while((skb = qeth_get_next_skb(card, buf->buffer, &element, |
| 2571 | &offset, &hdr))) { |
| 2572 | skb->dev = card->dev; |
| 2573 | if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) |
| 2574 | vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2575 | else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3) |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2576 | vlan_tag = qeth_rebuild_skb(card, skb, hdr); |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2577 | else { /*in case of OSN*/ |
| 2578 | skb_push(skb, sizeof(struct qeth_hdr)); |
| 2579 | memcpy(skb->data, hdr, sizeof(struct qeth_hdr)); |
| 2580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | /* is device UP ? */ |
| 2582 | if (!(card->dev->flags & IFF_UP)){ |
| 2583 | dev_kfree_skb_any(skb); |
| 2584 | continue; |
| 2585 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2586 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 2587 | rxrc = card->osn_info.data_cb(skb); |
| 2588 | else |
Frank Pavlic | 330b636 | 2006-09-15 16:25:56 +0200 | [diff] [blame] | 2589 | #ifdef CONFIG_QETH_VLAN |
| 2590 | if (vlan_tag) |
| 2591 | if (card->vlangrp) |
| 2592 | vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag); |
| 2593 | else { |
| 2594 | dev_kfree_skb_any(skb); |
| 2595 | continue; |
| 2596 | } |
| 2597 | else |
| 2598 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 2599 | rxrc = netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | card->dev->last_rx = jiffies; |
| 2601 | card->stats.rx_packets++; |
| 2602 | card->stats.rx_bytes += skb->len; |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | static inline struct qeth_buffer_pool_entry * |
| 2607 | qeth_get_buffer_pool_entry(struct qeth_card *card) |
| 2608 | { |
| 2609 | struct qeth_buffer_pool_entry *entry; |
| 2610 | |
| 2611 | QETH_DBF_TEXT(trace, 6, "gtbfplen"); |
| 2612 | if (!list_empty(&card->qdio.in_buf_pool.entry_list)) { |
| 2613 | entry = list_entry(card->qdio.in_buf_pool.entry_list.next, |
| 2614 | struct qeth_buffer_pool_entry, list); |
| 2615 | list_del_init(&entry->list); |
| 2616 | return entry; |
| 2617 | } |
| 2618 | return NULL; |
| 2619 | } |
| 2620 | |
| 2621 | static inline void |
| 2622 | qeth_init_input_buffer(struct qeth_card *card, struct qeth_qdio_buffer *buf) |
| 2623 | { |
| 2624 | struct qeth_buffer_pool_entry *pool_entry; |
| 2625 | int i; |
| 2626 | |
| 2627 | pool_entry = qeth_get_buffer_pool_entry(card); |
| 2628 | /* |
| 2629 | * since the buffer is accessed only from the input_tasklet |
| 2630 | * there shouldn't be a need to synchronize; also, since we use |
| 2631 | * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off |
| 2632 | * buffers |
| 2633 | */ |
| 2634 | BUG_ON(!pool_entry); |
| 2635 | |
| 2636 | buf->pool_entry = pool_entry; |
| 2637 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){ |
| 2638 | buf->buffer->element[i].length = PAGE_SIZE; |
| 2639 | buf->buffer->element[i].addr = pool_entry->elements[i]; |
| 2640 | if (i == QETH_MAX_BUFFER_ELEMENTS(card) - 1) |
| 2641 | buf->buffer->element[i].flags = SBAL_FLAGS_LAST_ENTRY; |
| 2642 | else |
| 2643 | buf->buffer->element[i].flags = 0; |
| 2644 | } |
| 2645 | buf->state = QETH_QDIO_BUF_EMPTY; |
| 2646 | } |
| 2647 | |
| 2648 | static inline void |
| 2649 | qeth_clear_output_buffer(struct qeth_qdio_out_q *queue, |
| 2650 | struct qeth_qdio_out_buffer *buf) |
| 2651 | { |
| 2652 | int i; |
| 2653 | struct sk_buff *skb; |
| 2654 | |
| 2655 | /* is PCI flag set on buffer? */ |
| 2656 | if (buf->buffer->element[0].flags & 0x40) |
| 2657 | atomic_dec(&queue->set_pci_flags_count); |
| 2658 | |
| 2659 | while ((skb = skb_dequeue(&buf->skb_list))){ |
| 2660 | atomic_dec(&skb->users); |
| 2661 | dev_kfree_skb_any(skb); |
| 2662 | } |
| 2663 | qeth_eddp_buf_release_contexts(buf); |
| 2664 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(queue->card); ++i){ |
| 2665 | buf->buffer->element[i].length = 0; |
| 2666 | buf->buffer->element[i].addr = NULL; |
| 2667 | buf->buffer->element[i].flags = 0; |
| 2668 | } |
| 2669 | buf->next_element_to_fill = 0; |
| 2670 | atomic_set(&buf->state, QETH_QDIO_BUF_EMPTY); |
| 2671 | } |
| 2672 | |
| 2673 | static inline void |
| 2674 | qeth_queue_input_buffer(struct qeth_card *card, int index) |
| 2675 | { |
| 2676 | struct qeth_qdio_q *queue = card->qdio.in_q; |
| 2677 | int count; |
| 2678 | int i; |
| 2679 | int rc; |
| 2680 | |
| 2681 | QETH_DBF_TEXT(trace,6,"queinbuf"); |
| 2682 | count = (index < queue->next_buf_to_init)? |
| 2683 | card->qdio.in_buf_pool.buf_count - |
| 2684 | (queue->next_buf_to_init - index) : |
| 2685 | card->qdio.in_buf_pool.buf_count - |
| 2686 | (queue->next_buf_to_init + QDIO_MAX_BUFFERS_PER_Q - index); |
| 2687 | /* only requeue at a certain threshold to avoid SIGAs */ |
| 2688 | if (count >= QETH_IN_BUF_REQUEUE_THRESHOLD(card)){ |
| 2689 | for (i = queue->next_buf_to_init; |
| 2690 | i < queue->next_buf_to_init + count; ++i) |
| 2691 | qeth_init_input_buffer(card, |
| 2692 | &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]); |
| 2693 | /* |
| 2694 | * according to old code it should be avoided to requeue all |
| 2695 | * 128 buffers in order to benefit from PCI avoidance. |
| 2696 | * this function keeps at least one buffer (the buffer at |
| 2697 | * 'index') un-requeued -> this buffer is the first buffer that |
| 2698 | * will be requeued the next time |
| 2699 | */ |
| 2700 | #ifdef CONFIG_QETH_PERF_STATS |
| 2701 | card->perf_stats.inbound_do_qdio_cnt++; |
| 2702 | card->perf_stats.inbound_do_qdio_start_time = qeth_get_micros(); |
| 2703 | #endif |
| 2704 | rc = do_QDIO(CARD_DDEV(card), |
| 2705 | QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT, |
| 2706 | 0, queue->next_buf_to_init, count, NULL); |
| 2707 | #ifdef CONFIG_QETH_PERF_STATS |
| 2708 | card->perf_stats.inbound_do_qdio_time += qeth_get_micros() - |
| 2709 | card->perf_stats.inbound_do_qdio_start_time; |
| 2710 | #endif |
| 2711 | if (rc){ |
| 2712 | PRINT_WARN("qeth_queue_input_buffer's do_QDIO " |
| 2713 | "return %i (device %s).\n", |
| 2714 | rc, CARD_DDEV_ID(card)); |
| 2715 | QETH_DBF_TEXT(trace,2,"qinberr"); |
| 2716 | QETH_DBF_TEXT_(trace,2,"%s",CARD_BUS_ID(card)); |
| 2717 | } |
| 2718 | queue->next_buf_to_init = (queue->next_buf_to_init + count) % |
| 2719 | QDIO_MAX_BUFFERS_PER_Q; |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | static inline void |
| 2724 | qeth_put_buffer_pool_entry(struct qeth_card *card, |
| 2725 | struct qeth_buffer_pool_entry *entry) |
| 2726 | { |
| 2727 | QETH_DBF_TEXT(trace, 6, "ptbfplen"); |
| 2728 | list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list); |
| 2729 | } |
| 2730 | |
| 2731 | static void |
| 2732 | qeth_qdio_input_handler(struct ccw_device * ccwdev, unsigned int status, |
| 2733 | unsigned int qdio_err, unsigned int siga_err, |
| 2734 | unsigned int queue, int first_element, int count, |
| 2735 | unsigned long card_ptr) |
| 2736 | { |
| 2737 | struct net_device *net_dev; |
| 2738 | struct qeth_card *card; |
| 2739 | struct qeth_qdio_buffer *buffer; |
| 2740 | int index; |
| 2741 | int i; |
| 2742 | |
| 2743 | QETH_DBF_TEXT(trace, 6, "qdinput"); |
| 2744 | card = (struct qeth_card *) card_ptr; |
| 2745 | net_dev = card->dev; |
| 2746 | #ifdef CONFIG_QETH_PERF_STATS |
| 2747 | card->perf_stats.inbound_cnt++; |
| 2748 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
| 2749 | #endif |
| 2750 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { |
| 2751 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){ |
| 2752 | QETH_DBF_TEXT(trace, 1,"qdinchk"); |
| 2753 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2754 | QETH_DBF_TEXT_(trace,1,"%04X%04X",first_element,count); |
| 2755 | QETH_DBF_TEXT_(trace,1,"%04X%04X", queue, status); |
| 2756 | qeth_schedule_recovery(card); |
| 2757 | return; |
| 2758 | } |
| 2759 | } |
| 2760 | for (i = first_element; i < (first_element + count); ++i) { |
| 2761 | index = i % QDIO_MAX_BUFFERS_PER_Q; |
| 2762 | buffer = &card->qdio.in_q->bufs[index]; |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2763 | if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2764 | qeth_check_qdio_errors(buffer->buffer, |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2765 | qdio_err, siga_err,"qinerr"))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | qeth_process_inbound_buffer(card, buffer, index); |
| 2767 | /* clear buffer and give back to hardware */ |
| 2768 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); |
| 2769 | qeth_queue_input_buffer(card, index); |
| 2770 | } |
| 2771 | #ifdef CONFIG_QETH_PERF_STATS |
| 2772 | card->perf_stats.inbound_time += qeth_get_micros() - |
| 2773 | card->perf_stats.inbound_start_time; |
| 2774 | #endif |
| 2775 | } |
| 2776 | |
| 2777 | static inline int |
| 2778 | qeth_handle_send_error(struct qeth_card *card, |
| 2779 | struct qeth_qdio_out_buffer *buffer, |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2780 | unsigned int qdio_err, unsigned int siga_err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | { |
| 2782 | int sbalf15 = buffer->buffer->element[15].flags & 0xff; |
| 2783 | int cc = siga_err & 3; |
| 2784 | |
| 2785 | QETH_DBF_TEXT(trace, 6, "hdsnderr"); |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 2786 | qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | switch (cc) { |
| 2788 | case 0: |
| 2789 | if (qdio_err){ |
| 2790 | QETH_DBF_TEXT(trace, 1,"lnkfail"); |
| 2791 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2792 | QETH_DBF_TEXT_(trace,1,"%04x %02x", |
| 2793 | (u16)qdio_err, (u8)sbalf15); |
| 2794 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2795 | } |
| 2796 | return QETH_SEND_ERROR_NONE; |
| 2797 | case 2: |
| 2798 | if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) { |
| 2799 | QETH_DBF_TEXT(trace, 1, "SIGAcc2B"); |
| 2800 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2801 | return QETH_SEND_ERROR_KICK_IT; |
| 2802 | } |
| 2803 | if ((sbalf15 >= 15) && (sbalf15 <= 31)) |
| 2804 | return QETH_SEND_ERROR_RETRY; |
| 2805 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2806 | /* look at qdio_error and sbalf 15 */ |
| 2807 | case 1: |
| 2808 | QETH_DBF_TEXT(trace, 1, "SIGAcc1"); |
| 2809 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2810 | return QETH_SEND_ERROR_LINK_FAILURE; |
| 2811 | case 3: |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 2812 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | QETH_DBF_TEXT(trace, 1, "SIGAcc3"); |
| 2814 | QETH_DBF_TEXT_(trace,1,"%s",CARD_BUS_ID(card)); |
| 2815 | return QETH_SEND_ERROR_KICK_IT; |
| 2816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | void |
| 2820 | qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int, |
| 2821 | int index, int count) |
| 2822 | { |
| 2823 | struct qeth_qdio_out_buffer *buf; |
| 2824 | int rc; |
| 2825 | int i; |
| 2826 | |
| 2827 | QETH_DBF_TEXT(trace, 6, "flushbuf"); |
| 2828 | |
| 2829 | for (i = index; i < index + count; ++i) { |
| 2830 | buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; |
| 2831 | buf->buffer->element[buf->next_element_to_fill - 1].flags |= |
| 2832 | SBAL_FLAGS_LAST_ENTRY; |
| 2833 | |
| 2834 | if (queue->card->info.type == QETH_CARD_TYPE_IQD) |
| 2835 | continue; |
| 2836 | |
| 2837 | if (!queue->do_pack){ |
| 2838 | if ((atomic_read(&queue->used_buffers) >= |
| 2839 | (QETH_HIGH_WATERMARK_PACK - |
| 2840 | QETH_WATERMARK_PACK_FUZZ)) && |
| 2841 | !atomic_read(&queue->set_pci_flags_count)){ |
| 2842 | /* it's likely that we'll go to packing |
| 2843 | * mode soon */ |
| 2844 | atomic_inc(&queue->set_pci_flags_count); |
| 2845 | buf->buffer->element[0].flags |= 0x40; |
| 2846 | } |
| 2847 | } else { |
| 2848 | if (!atomic_read(&queue->set_pci_flags_count)){ |
| 2849 | /* |
| 2850 | * there's no outstanding PCI any more, so we |
| 2851 | * have to request a PCI to be sure the the PCI |
| 2852 | * will wake at some time in the future then we |
| 2853 | * can flush packed buffers that might still be |
| 2854 | * hanging around, which can happen if no |
| 2855 | * further send was requested by the stack |
| 2856 | */ |
| 2857 | atomic_inc(&queue->set_pci_flags_count); |
| 2858 | buf->buffer->element[0].flags |= 0x40; |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | queue->card->dev->trans_start = jiffies; |
| 2864 | #ifdef CONFIG_QETH_PERF_STATS |
| 2865 | queue->card->perf_stats.outbound_do_qdio_cnt++; |
| 2866 | queue->card->perf_stats.outbound_do_qdio_start_time = qeth_get_micros(); |
| 2867 | #endif |
| 2868 | if (under_int) |
| 2869 | rc = do_QDIO(CARD_DDEV(queue->card), |
| 2870 | QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT, |
| 2871 | queue->queue_no, index, count, NULL); |
| 2872 | else |
| 2873 | rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT, |
| 2874 | queue->queue_no, index, count, NULL); |
| 2875 | #ifdef CONFIG_QETH_PERF_STATS |
| 2876 | queue->card->perf_stats.outbound_do_qdio_time += qeth_get_micros() - |
| 2877 | queue->card->perf_stats.outbound_do_qdio_start_time; |
| 2878 | #endif |
| 2879 | if (rc){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | QETH_DBF_TEXT(trace, 2, "flushbuf"); |
| 2881 | QETH_DBF_TEXT_(trace, 2, " err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 2882 | QETH_DBF_TEXT_(trace, 2, "%s", CARD_DDEV_ID(queue->card)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | queue->card->stats.tx_errors += count; |
| 2884 | /* this must not happen under normal circumstances. if it |
| 2885 | * happens something is really wrong -> recover */ |
| 2886 | qeth_schedule_recovery(queue->card); |
| 2887 | return; |
| 2888 | } |
| 2889 | atomic_add(count, &queue->used_buffers); |
| 2890 | #ifdef CONFIG_QETH_PERF_STATS |
| 2891 | queue->card->perf_stats.bufs_sent += count; |
| 2892 | #endif |
| 2893 | } |
| 2894 | |
| 2895 | /* |
| 2896 | * Switched to packing state if the number of used buffers on a queue |
| 2897 | * reaches a certain limit. |
| 2898 | */ |
| 2899 | static inline void |
| 2900 | qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q *queue) |
| 2901 | { |
| 2902 | if (!queue->do_pack) { |
| 2903 | if (atomic_read(&queue->used_buffers) |
| 2904 | >= QETH_HIGH_WATERMARK_PACK){ |
| 2905 | /* switch non-PACKING -> PACKING */ |
| 2906 | QETH_DBF_TEXT(trace, 6, "np->pack"); |
| 2907 | #ifdef CONFIG_QETH_PERF_STATS |
| 2908 | queue->card->perf_stats.sc_dp_p++; |
| 2909 | #endif |
| 2910 | queue->do_pack = 1; |
| 2911 | } |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | /* |
| 2916 | * Switches from packing to non-packing mode. If there is a packing |
| 2917 | * buffer on the queue this buffer will be prepared to be flushed. |
| 2918 | * In that case 1 is returned to inform the caller. If no buffer |
| 2919 | * has to be flushed, zero is returned. |
| 2920 | */ |
| 2921 | static inline int |
| 2922 | qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q *queue) |
| 2923 | { |
| 2924 | struct qeth_qdio_out_buffer *buffer; |
| 2925 | int flush_count = 0; |
| 2926 | |
| 2927 | if (queue->do_pack) { |
| 2928 | if (atomic_read(&queue->used_buffers) |
| 2929 | <= QETH_LOW_WATERMARK_PACK) { |
| 2930 | /* switch PACKING -> non-PACKING */ |
| 2931 | QETH_DBF_TEXT(trace, 6, "pack->np"); |
| 2932 | #ifdef CONFIG_QETH_PERF_STATS |
| 2933 | queue->card->perf_stats.sc_p_dp++; |
| 2934 | #endif |
| 2935 | queue->do_pack = 0; |
| 2936 | /* flush packing buffers */ |
| 2937 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 2938 | if ((atomic_read(&buffer->state) == |
| 2939 | QETH_QDIO_BUF_EMPTY) && |
| 2940 | (buffer->next_element_to_fill > 0)) { |
| 2941 | atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED); |
| 2942 | flush_count++; |
| 2943 | queue->next_buf_to_fill = |
| 2944 | (queue->next_buf_to_fill + 1) % |
| 2945 | QDIO_MAX_BUFFERS_PER_Q; |
| 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | return flush_count; |
| 2950 | } |
| 2951 | |
| 2952 | /* |
| 2953 | * Called to flush a packing buffer if no more pci flags are on the queue. |
| 2954 | * Checks if there is a packing buffer and prepares it to be flushed. |
| 2955 | * In that case returns 1, otherwise zero. |
| 2956 | */ |
| 2957 | static inline int |
| 2958 | qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue) |
| 2959 | { |
| 2960 | struct qeth_qdio_out_buffer *buffer; |
| 2961 | |
| 2962 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 2963 | if((atomic_read(&buffer->state) == QETH_QDIO_BUF_EMPTY) && |
| 2964 | (buffer->next_element_to_fill > 0)){ |
| 2965 | /* it's a packing buffer */ |
| 2966 | atomic_set(&buffer->state, QETH_QDIO_BUF_PRIMED); |
| 2967 | queue->next_buf_to_fill = |
| 2968 | (queue->next_buf_to_fill + 1) % QDIO_MAX_BUFFERS_PER_Q; |
| 2969 | return 1; |
| 2970 | } |
| 2971 | return 0; |
| 2972 | } |
| 2973 | |
| 2974 | static inline void |
| 2975 | qeth_check_outbound_queue(struct qeth_qdio_out_q *queue) |
| 2976 | { |
| 2977 | int index; |
| 2978 | int flush_cnt = 0; |
| 2979 | int q_was_packing = 0; |
| 2980 | |
| 2981 | /* |
| 2982 | * check if weed have to switch to non-packing mode or if |
| 2983 | * we have to get a pci flag out on the queue |
| 2984 | */ |
| 2985 | if ((atomic_read(&queue->used_buffers) <= QETH_LOW_WATERMARK_PACK) || |
| 2986 | !atomic_read(&queue->set_pci_flags_count)){ |
| 2987 | if (atomic_swap(&queue->state, QETH_OUT_Q_LOCKED_FLUSH) == |
| 2988 | QETH_OUT_Q_UNLOCKED) { |
| 2989 | /* |
| 2990 | * If we get in here, there was no action in |
| 2991 | * do_send_packet. So, we check if there is a |
| 2992 | * packing buffer to be flushed here. |
| 2993 | */ |
| 2994 | netif_stop_queue(queue->card->dev); |
| 2995 | index = queue->next_buf_to_fill; |
| 2996 | q_was_packing = queue->do_pack; |
| 2997 | flush_cnt += qeth_switch_to_nonpacking_if_needed(queue); |
| 2998 | if (!flush_cnt && |
| 2999 | !atomic_read(&queue->set_pci_flags_count)) |
| 3000 | flush_cnt += |
| 3001 | qeth_flush_buffers_on_no_pci(queue); |
| 3002 | #ifdef CONFIG_QETH_PERF_STATS |
| 3003 | if (q_was_packing) |
| 3004 | queue->card->perf_stats.bufs_sent_pack += |
| 3005 | flush_cnt; |
| 3006 | #endif |
| 3007 | if (flush_cnt) |
| 3008 | qeth_flush_buffers(queue, 1, index, flush_cnt); |
| 3009 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 3010 | } |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | static void |
| 3015 | qeth_qdio_output_handler(struct ccw_device * ccwdev, unsigned int status, |
| 3016 | unsigned int qdio_error, unsigned int siga_error, |
| 3017 | unsigned int __queue, int first_element, int count, |
| 3018 | unsigned long card_ptr) |
| 3019 | { |
| 3020 | struct qeth_card *card = (struct qeth_card *) card_ptr; |
| 3021 | struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue]; |
| 3022 | struct qeth_qdio_out_buffer *buffer; |
| 3023 | int i; |
| 3024 | |
| 3025 | QETH_DBF_TEXT(trace, 6, "qdouhdl"); |
| 3026 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { |
| 3027 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION){ |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3028 | QETH_DBF_TEXT(trace, 2, "achkcond"); |
| 3029 | QETH_DBF_TEXT_(trace, 2, "%s", CARD_BUS_ID(card)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | QETH_DBF_TEXT_(trace, 2, "%08x", status); |
| 3031 | netif_stop_queue(card->dev); |
| 3032 | qeth_schedule_recovery(card); |
| 3033 | return; |
| 3034 | } |
| 3035 | } |
| 3036 | #ifdef CONFIG_QETH_PERF_STATS |
| 3037 | card->perf_stats.outbound_handler_cnt++; |
| 3038 | card->perf_stats.outbound_handler_start_time = qeth_get_micros(); |
| 3039 | #endif |
| 3040 | for(i = first_element; i < (first_element + count); ++i){ |
| 3041 | buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; |
| 3042 | /*we only handle the KICK_IT error by doing a recovery */ |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 3043 | if (qeth_handle_send_error(card, buffer, |
| 3044 | qdio_error, siga_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | == QETH_SEND_ERROR_KICK_IT){ |
| 3046 | netif_stop_queue(card->dev); |
| 3047 | qeth_schedule_recovery(card); |
| 3048 | return; |
| 3049 | } |
| 3050 | qeth_clear_output_buffer(queue, buffer); |
| 3051 | } |
| 3052 | atomic_sub(count, &queue->used_buffers); |
| 3053 | /* check if we need to do something on this outbound queue */ |
| 3054 | if (card->info.type != QETH_CARD_TYPE_IQD) |
| 3055 | qeth_check_outbound_queue(queue); |
| 3056 | |
| 3057 | netif_wake_queue(queue->card->dev); |
| 3058 | #ifdef CONFIG_QETH_PERF_STATS |
| 3059 | card->perf_stats.outbound_handler_time += qeth_get_micros() - |
| 3060 | card->perf_stats.outbound_handler_start_time; |
| 3061 | #endif |
| 3062 | } |
| 3063 | |
| 3064 | static void |
| 3065 | qeth_create_qib_param_field(struct qeth_card *card, char *param_field) |
| 3066 | { |
| 3067 | |
| 3068 | param_field[0] = _ascebc['P']; |
| 3069 | param_field[1] = _ascebc['C']; |
| 3070 | param_field[2] = _ascebc['I']; |
| 3071 | param_field[3] = _ascebc['T']; |
| 3072 | *((unsigned int *) (¶m_field[4])) = QETH_PCI_THRESHOLD_A(card); |
| 3073 | *((unsigned int *) (¶m_field[8])) = QETH_PCI_THRESHOLD_B(card); |
| 3074 | *((unsigned int *) (¶m_field[12])) = QETH_PCI_TIMER_VALUE(card); |
| 3075 | } |
| 3076 | |
| 3077 | static void |
| 3078 | qeth_create_qib_param_field_blkt(struct qeth_card *card, char *param_field) |
| 3079 | { |
| 3080 | param_field[16] = _ascebc['B']; |
| 3081 | param_field[17] = _ascebc['L']; |
| 3082 | param_field[18] = _ascebc['K']; |
| 3083 | param_field[19] = _ascebc['T']; |
| 3084 | *((unsigned int *) (¶m_field[20])) = card->info.blkt.time_total; |
| 3085 | *((unsigned int *) (¶m_field[24])) = card->info.blkt.inter_packet; |
| 3086 | *((unsigned int *) (¶m_field[28])) = card->info.blkt.inter_packet_jumbo; |
| 3087 | } |
| 3088 | |
| 3089 | static void |
| 3090 | qeth_initialize_working_pool_list(struct qeth_card *card) |
| 3091 | { |
| 3092 | struct qeth_buffer_pool_entry *entry; |
| 3093 | |
| 3094 | QETH_DBF_TEXT(trace,5,"inwrklst"); |
| 3095 | |
| 3096 | list_for_each_entry(entry, |
| 3097 | &card->qdio.init_pool.entry_list, init_list) { |
| 3098 | qeth_put_buffer_pool_entry(card,entry); |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | static void |
| 3103 | qeth_clear_working_pool_list(struct qeth_card *card) |
| 3104 | { |
| 3105 | struct qeth_buffer_pool_entry *pool_entry, *tmp; |
| 3106 | |
| 3107 | QETH_DBF_TEXT(trace,5,"clwrklst"); |
| 3108 | list_for_each_entry_safe(pool_entry, tmp, |
| 3109 | &card->qdio.in_buf_pool.entry_list, list){ |
| 3110 | list_del(&pool_entry->list); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | static void |
| 3115 | qeth_free_buffer_pool(struct qeth_card *card) |
| 3116 | { |
| 3117 | struct qeth_buffer_pool_entry *pool_entry, *tmp; |
| 3118 | int i=0; |
| 3119 | QETH_DBF_TEXT(trace,5,"freepool"); |
| 3120 | list_for_each_entry_safe(pool_entry, tmp, |
| 3121 | &card->qdio.init_pool.entry_list, init_list){ |
| 3122 | for (i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i) |
| 3123 | free_page((unsigned long)pool_entry->elements[i]); |
| 3124 | list_del(&pool_entry->init_list); |
| 3125 | kfree(pool_entry); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | static int |
| 3130 | qeth_alloc_buffer_pool(struct qeth_card *card) |
| 3131 | { |
| 3132 | struct qeth_buffer_pool_entry *pool_entry; |
| 3133 | void *ptr; |
| 3134 | int i, j; |
| 3135 | |
| 3136 | QETH_DBF_TEXT(trace,5,"alocpool"); |
| 3137 | for (i = 0; i < card->qdio.init_pool.buf_count; ++i){ |
| 3138 | pool_entry = kmalloc(sizeof(*pool_entry), GFP_KERNEL); |
| 3139 | if (!pool_entry){ |
| 3140 | qeth_free_buffer_pool(card); |
| 3141 | return -ENOMEM; |
| 3142 | } |
| 3143 | for(j = 0; j < QETH_MAX_BUFFER_ELEMENTS(card); ++j){ |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3144 | ptr = (void *) __get_free_page(GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | if (!ptr) { |
| 3146 | while (j > 0) |
| 3147 | free_page((unsigned long) |
| 3148 | pool_entry->elements[--j]); |
| 3149 | kfree(pool_entry); |
| 3150 | qeth_free_buffer_pool(card); |
| 3151 | return -ENOMEM; |
| 3152 | } |
| 3153 | pool_entry->elements[j] = ptr; |
| 3154 | } |
| 3155 | list_add(&pool_entry->init_list, |
| 3156 | &card->qdio.init_pool.entry_list); |
| 3157 | } |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
| 3161 | int |
| 3162 | qeth_realloc_buffer_pool(struct qeth_card *card, int bufcnt) |
| 3163 | { |
| 3164 | QETH_DBF_TEXT(trace, 2, "realcbp"); |
| 3165 | |
| 3166 | if ((card->state != CARD_STATE_DOWN) && |
| 3167 | (card->state != CARD_STATE_RECOVER)) |
| 3168 | return -EPERM; |
| 3169 | |
| 3170 | /* TODO: steel/add buffers from/to a running card's buffer pool (?) */ |
| 3171 | qeth_clear_working_pool_list(card); |
| 3172 | qeth_free_buffer_pool(card); |
| 3173 | card->qdio.in_buf_pool.buf_count = bufcnt; |
| 3174 | card->qdio.init_pool.buf_count = bufcnt; |
| 3175 | return qeth_alloc_buffer_pool(card); |
| 3176 | } |
| 3177 | |
| 3178 | static int |
| 3179 | qeth_alloc_qdio_buffers(struct qeth_card *card) |
| 3180 | { |
| 3181 | int i, j; |
| 3182 | |
| 3183 | QETH_DBF_TEXT(setup, 2, "allcqdbf"); |
| 3184 | |
| 3185 | if (card->qdio.state == QETH_QDIO_ALLOCATED) |
| 3186 | return 0; |
| 3187 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3188 | card->qdio.in_q = kmalloc(sizeof(struct qeth_qdio_q), |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3189 | GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | if (!card->qdio.in_q) |
| 3191 | return - ENOMEM; |
| 3192 | QETH_DBF_TEXT(setup, 2, "inq"); |
| 3193 | QETH_DBF_HEX(setup, 2, &card->qdio.in_q, sizeof(void *)); |
| 3194 | memset(card->qdio.in_q, 0, sizeof(struct qeth_qdio_q)); |
| 3195 | /* give inbound qeth_qdio_buffers their qdio_buffers */ |
| 3196 | for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) |
| 3197 | card->qdio.in_q->bufs[i].buffer = |
| 3198 | &card->qdio.in_q->qdio_bufs[i]; |
| 3199 | /* inbound buffer pool */ |
| 3200 | if (qeth_alloc_buffer_pool(card)){ |
| 3201 | kfree(card->qdio.in_q); |
| 3202 | return -ENOMEM; |
| 3203 | } |
| 3204 | /* outbound */ |
| 3205 | card->qdio.out_qs = |
| 3206 | kmalloc(card->qdio.no_out_queues * |
| 3207 | sizeof(struct qeth_qdio_out_q *), GFP_KERNEL); |
| 3208 | if (!card->qdio.out_qs){ |
| 3209 | qeth_free_buffer_pool(card); |
| 3210 | return -ENOMEM; |
| 3211 | } |
| 3212 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3213 | card->qdio.out_qs[i] = kmalloc(sizeof(struct qeth_qdio_out_q), |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 3214 | GFP_KERNEL|GFP_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | if (!card->qdio.out_qs[i]){ |
| 3216 | while (i > 0) |
| 3217 | kfree(card->qdio.out_qs[--i]); |
| 3218 | kfree(card->qdio.out_qs); |
| 3219 | return -ENOMEM; |
| 3220 | } |
| 3221 | QETH_DBF_TEXT_(setup, 2, "outq %i", i); |
| 3222 | QETH_DBF_HEX(setup, 2, &card->qdio.out_qs[i], sizeof(void *)); |
| 3223 | memset(card->qdio.out_qs[i], 0, sizeof(struct qeth_qdio_out_q)); |
| 3224 | card->qdio.out_qs[i]->queue_no = i; |
| 3225 | /* give outbound qeth_qdio_buffers their qdio_buffers */ |
| 3226 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){ |
| 3227 | card->qdio.out_qs[i]->bufs[j].buffer = |
| 3228 | &card->qdio.out_qs[i]->qdio_bufs[j]; |
| 3229 | skb_queue_head_init(&card->qdio.out_qs[i]->bufs[j]. |
| 3230 | skb_list); |
Heiko Carstens | 91ebe2a | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 3231 | lockdep_set_class( |
| 3232 | &card->qdio.out_qs[i]->bufs[j].skb_list.lock, |
| 3233 | &qdio_out_skb_queue_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | INIT_LIST_HEAD(&card->qdio.out_qs[i]->bufs[j].ctx_list); |
| 3235 | } |
| 3236 | } |
| 3237 | card->qdio.state = QETH_QDIO_ALLOCATED; |
| 3238 | return 0; |
| 3239 | } |
| 3240 | |
| 3241 | static void |
| 3242 | qeth_free_qdio_buffers(struct qeth_card *card) |
| 3243 | { |
| 3244 | int i, j; |
| 3245 | |
| 3246 | QETH_DBF_TEXT(trace, 2, "freeqdbf"); |
| 3247 | if (card->qdio.state == QETH_QDIO_UNINITIALIZED) |
| 3248 | return; |
| 3249 | kfree(card->qdio.in_q); |
| 3250 | /* inbound buffer pool */ |
| 3251 | qeth_free_buffer_pool(card); |
| 3252 | /* free outbound qdio_qs */ |
| 3253 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3254 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 3255 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3256 | &card->qdio.out_qs[i]->bufs[j]); |
| 3257 | kfree(card->qdio.out_qs[i]); |
| 3258 | } |
| 3259 | kfree(card->qdio.out_qs); |
| 3260 | card->qdio.state = QETH_QDIO_UNINITIALIZED; |
| 3261 | } |
| 3262 | |
| 3263 | static void |
| 3264 | qeth_clear_qdio_buffers(struct qeth_card *card) |
| 3265 | { |
| 3266 | int i, j; |
| 3267 | |
| 3268 | QETH_DBF_TEXT(trace, 2, "clearqdbf"); |
| 3269 | /* clear outbound buffers to free skbs */ |
| 3270 | for (i = 0; i < card->qdio.no_out_queues; ++i) |
| 3271 | if (card->qdio.out_qs[i]){ |
| 3272 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 3273 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3274 | &card->qdio.out_qs[i]->bufs[j]); |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | static void |
| 3279 | qeth_init_qdio_info(struct qeth_card *card) |
| 3280 | { |
| 3281 | QETH_DBF_TEXT(setup, 4, "intqdinf"); |
| 3282 | card->qdio.state = QETH_QDIO_UNINITIALIZED; |
| 3283 | /* inbound */ |
| 3284 | card->qdio.in_buf_size = QETH_IN_BUF_SIZE_DEFAULT; |
| 3285 | card->qdio.init_pool.buf_count = QETH_IN_BUF_COUNT_DEFAULT; |
| 3286 | card->qdio.in_buf_pool.buf_count = card->qdio.init_pool.buf_count; |
| 3287 | INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list); |
| 3288 | INIT_LIST_HEAD(&card->qdio.init_pool.entry_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | static int |
| 3292 | qeth_init_qdio_queues(struct qeth_card *card) |
| 3293 | { |
| 3294 | int i, j; |
| 3295 | int rc; |
| 3296 | |
| 3297 | QETH_DBF_TEXT(setup, 2, "initqdqs"); |
| 3298 | |
| 3299 | /* inbound queue */ |
| 3300 | memset(card->qdio.in_q->qdio_bufs, 0, |
| 3301 | QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer)); |
| 3302 | qeth_initialize_working_pool_list(card); |
| 3303 | /*give only as many buffers to hardware as we have buffer pool entries*/ |
| 3304 | for (i = 0; i < card->qdio.in_buf_pool.buf_count - 1; ++i) |
| 3305 | qeth_init_input_buffer(card, &card->qdio.in_q->bufs[i]); |
| 3306 | card->qdio.in_q->next_buf_to_init = card->qdio.in_buf_pool.buf_count - 1; |
| 3307 | rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, |
| 3308 | card->qdio.in_buf_pool.buf_count - 1, NULL); |
| 3309 | if (rc) { |
| 3310 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 3311 | return rc; |
| 3312 | } |
| 3313 | rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0); |
| 3314 | if (rc) { |
| 3315 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 3316 | return rc; |
| 3317 | } |
| 3318 | /* outbound queue */ |
| 3319 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 3320 | memset(card->qdio.out_qs[i]->qdio_bufs, 0, |
| 3321 | QDIO_MAX_BUFFERS_PER_Q * sizeof(struct qdio_buffer)); |
| 3322 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j){ |
| 3323 | qeth_clear_output_buffer(card->qdio.out_qs[i], |
| 3324 | &card->qdio.out_qs[i]->bufs[j]); |
| 3325 | } |
| 3326 | card->qdio.out_qs[i]->card = card; |
| 3327 | card->qdio.out_qs[i]->next_buf_to_fill = 0; |
| 3328 | card->qdio.out_qs[i]->do_pack = 0; |
| 3329 | atomic_set(&card->qdio.out_qs[i]->used_buffers,0); |
| 3330 | atomic_set(&card->qdio.out_qs[i]->set_pci_flags_count, 0); |
| 3331 | atomic_set(&card->qdio.out_qs[i]->state, |
| 3332 | QETH_OUT_Q_UNLOCKED); |
| 3333 | } |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
| 3337 | static int |
| 3338 | qeth_qdio_establish(struct qeth_card *card) |
| 3339 | { |
| 3340 | struct qdio_initialize init_data; |
| 3341 | char *qib_param_field; |
| 3342 | struct qdio_buffer **in_sbal_ptrs; |
| 3343 | struct qdio_buffer **out_sbal_ptrs; |
| 3344 | int i, j, k; |
| 3345 | int rc; |
| 3346 | |
| 3347 | QETH_DBF_TEXT(setup, 2, "qdioest"); |
| 3348 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 3349 | qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | GFP_KERNEL); |
| 3351 | if (!qib_param_field) |
| 3352 | return -ENOMEM; |
| 3353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | qeth_create_qib_param_field(card, qib_param_field); |
| 3355 | qeth_create_qib_param_field_blkt(card, qib_param_field); |
| 3356 | |
| 3357 | in_sbal_ptrs = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(void *), |
| 3358 | GFP_KERNEL); |
| 3359 | if (!in_sbal_ptrs) { |
| 3360 | kfree(qib_param_field); |
| 3361 | return -ENOMEM; |
| 3362 | } |
| 3363 | for(i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i) |
| 3364 | in_sbal_ptrs[i] = (struct qdio_buffer *) |
| 3365 | virt_to_phys(card->qdio.in_q->bufs[i].buffer); |
| 3366 | |
| 3367 | out_sbal_ptrs = |
| 3368 | kmalloc(card->qdio.no_out_queues * QDIO_MAX_BUFFERS_PER_Q * |
| 3369 | sizeof(void *), GFP_KERNEL); |
| 3370 | if (!out_sbal_ptrs) { |
| 3371 | kfree(in_sbal_ptrs); |
| 3372 | kfree(qib_param_field); |
| 3373 | return -ENOMEM; |
| 3374 | } |
| 3375 | for(i = 0, k = 0; i < card->qdio.no_out_queues; ++i) |
| 3376 | for(j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j, ++k){ |
| 3377 | out_sbal_ptrs[k] = (struct qdio_buffer *) |
| 3378 | virt_to_phys(card->qdio.out_qs[i]-> |
| 3379 | bufs[j].buffer); |
| 3380 | } |
| 3381 | |
| 3382 | memset(&init_data, 0, sizeof(struct qdio_initialize)); |
| 3383 | init_data.cdev = CARD_DDEV(card); |
| 3384 | init_data.q_format = qeth_get_qdio_q_format(card); |
| 3385 | init_data.qib_param_field_format = 0; |
| 3386 | init_data.qib_param_field = qib_param_field; |
| 3387 | init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD; |
| 3388 | init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD; |
| 3389 | init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD; |
| 3390 | init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD; |
| 3391 | init_data.no_input_qs = 1; |
| 3392 | init_data.no_output_qs = card->qdio.no_out_queues; |
| 3393 | init_data.input_handler = (qdio_handler_t *) |
| 3394 | qeth_qdio_input_handler; |
| 3395 | init_data.output_handler = (qdio_handler_t *) |
| 3396 | qeth_qdio_output_handler; |
| 3397 | init_data.int_parm = (unsigned long) card; |
| 3398 | init_data.flags = QDIO_INBOUND_0COPY_SBALS | |
| 3399 | QDIO_OUTBOUND_0COPY_SBALS | |
| 3400 | QDIO_USE_OUTBOUND_PCIS; |
| 3401 | init_data.input_sbal_addr_array = (void **) in_sbal_ptrs; |
| 3402 | init_data.output_sbal_addr_array = (void **) out_sbal_ptrs; |
| 3403 | |
| 3404 | if (!(rc = qdio_initialize(&init_data))) |
| 3405 | card->qdio.state = QETH_QDIO_ESTABLISHED; |
| 3406 | |
| 3407 | kfree(out_sbal_ptrs); |
| 3408 | kfree(in_sbal_ptrs); |
| 3409 | kfree(qib_param_field); |
| 3410 | return rc; |
| 3411 | } |
| 3412 | |
| 3413 | static int |
| 3414 | qeth_qdio_activate(struct qeth_card *card) |
| 3415 | { |
| 3416 | QETH_DBF_TEXT(setup,3,"qdioact"); |
| 3417 | return qdio_activate(CARD_DDEV(card), 0); |
| 3418 | } |
| 3419 | |
| 3420 | static int |
| 3421 | qeth_clear_channel(struct qeth_channel *channel) |
| 3422 | { |
| 3423 | unsigned long flags; |
| 3424 | struct qeth_card *card; |
| 3425 | int rc; |
| 3426 | |
| 3427 | QETH_DBF_TEXT(trace,3,"clearch"); |
| 3428 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 3429 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 3430 | rc = ccw_device_clear(channel->ccwdev, QETH_CLEAR_CHANNEL_PARM); |
| 3431 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 3432 | |
| 3433 | if (rc) |
| 3434 | return rc; |
| 3435 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 3436 | channel->state==CH_STATE_STOPPED, QETH_TIMEOUT); |
| 3437 | if (rc == -ERESTARTSYS) |
| 3438 | return rc; |
| 3439 | if (channel->state != CH_STATE_STOPPED) |
| 3440 | return -ETIME; |
| 3441 | channel->state = CH_STATE_DOWN; |
| 3442 | return 0; |
| 3443 | } |
| 3444 | |
| 3445 | static int |
| 3446 | qeth_halt_channel(struct qeth_channel *channel) |
| 3447 | { |
| 3448 | unsigned long flags; |
| 3449 | struct qeth_card *card; |
| 3450 | int rc; |
| 3451 | |
| 3452 | QETH_DBF_TEXT(trace,3,"haltch"); |
| 3453 | card = CARD_FROM_CDEV(channel->ccwdev); |
| 3454 | spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); |
| 3455 | rc = ccw_device_halt(channel->ccwdev, QETH_HALT_CHANNEL_PARM); |
| 3456 | spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); |
| 3457 | |
| 3458 | if (rc) |
| 3459 | return rc; |
| 3460 | rc = wait_event_interruptible_timeout(card->wait_q, |
| 3461 | channel->state==CH_STATE_HALTED, QETH_TIMEOUT); |
| 3462 | if (rc == -ERESTARTSYS) |
| 3463 | return rc; |
| 3464 | if (channel->state != CH_STATE_HALTED) |
| 3465 | return -ETIME; |
| 3466 | return 0; |
| 3467 | } |
| 3468 | |
| 3469 | static int |
| 3470 | qeth_halt_channels(struct qeth_card *card) |
| 3471 | { |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3472 | int rc1 = 0, rc2=0, rc3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
| 3474 | QETH_DBF_TEXT(trace,3,"haltchs"); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3475 | rc1 = qeth_halt_channel(&card->read); |
| 3476 | rc2 = qeth_halt_channel(&card->write); |
| 3477 | rc3 = qeth_halt_channel(&card->data); |
| 3478 | if (rc1) |
| 3479 | return rc1; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3480 | if (rc2) |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3481 | return rc2; |
| 3482 | return rc3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | static int |
| 3485 | qeth_clear_channels(struct qeth_card *card) |
| 3486 | { |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3487 | int rc1 = 0, rc2=0, rc3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | |
| 3489 | QETH_DBF_TEXT(trace,3,"clearchs"); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3490 | rc1 = qeth_clear_channel(&card->read); |
| 3491 | rc2 = qeth_clear_channel(&card->write); |
| 3492 | rc3 = qeth_clear_channel(&card->data); |
| 3493 | if (rc1) |
| 3494 | return rc1; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3495 | if (rc2) |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3496 | return rc2; |
| 3497 | return rc3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | static int |
| 3501 | qeth_clear_halt_card(struct qeth_card *card, int halt) |
| 3502 | { |
| 3503 | int rc = 0; |
| 3504 | |
| 3505 | QETH_DBF_TEXT(trace,3,"clhacrd"); |
| 3506 | QETH_DBF_HEX(trace, 3, &card, sizeof(void *)); |
| 3507 | |
| 3508 | if (halt) |
| 3509 | rc = qeth_halt_channels(card); |
| 3510 | if (rc) |
| 3511 | return rc; |
| 3512 | return qeth_clear_channels(card); |
| 3513 | } |
| 3514 | |
| 3515 | static int |
| 3516 | qeth_qdio_clear_card(struct qeth_card *card, int use_halt) |
| 3517 | { |
| 3518 | int rc = 0; |
| 3519 | |
| 3520 | QETH_DBF_TEXT(trace,3,"qdioclr"); |
| 3521 | if (card->qdio.state == QETH_QDIO_ESTABLISHED){ |
| 3522 | if ((rc = qdio_cleanup(CARD_DDEV(card), |
| 3523 | (card->info.type == QETH_CARD_TYPE_IQD) ? |
| 3524 | QDIO_FLAG_CLEANUP_USING_HALT : |
| 3525 | QDIO_FLAG_CLEANUP_USING_CLEAR))) |
| 3526 | QETH_DBF_TEXT_(trace, 3, "1err%d", rc); |
| 3527 | card->qdio.state = QETH_QDIO_ALLOCATED; |
| 3528 | } |
| 3529 | if ((rc = qeth_clear_halt_card(card, use_halt))) |
| 3530 | QETH_DBF_TEXT_(trace, 3, "2err%d", rc); |
| 3531 | card->state = CARD_STATE_DOWN; |
| 3532 | return rc; |
| 3533 | } |
| 3534 | |
| 3535 | static int |
| 3536 | qeth_dm_act(struct qeth_card *card) |
| 3537 | { |
| 3538 | int rc; |
| 3539 | struct qeth_cmd_buffer *iob; |
| 3540 | |
| 3541 | QETH_DBF_TEXT(setup,2,"dmact"); |
| 3542 | |
| 3543 | iob = qeth_wait_for_buffer(&card->write); |
| 3544 | memcpy(iob->data, DM_ACT, DM_ACT_SIZE); |
| 3545 | |
| 3546 | memcpy(QETH_DM_ACT_DEST_ADDR(iob->data), |
| 3547 | &card->token.cm_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 3548 | memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob->data), |
| 3549 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 3550 | rc = qeth_send_control_data(card, DM_ACT_SIZE, iob, NULL, NULL); |
| 3551 | return rc; |
| 3552 | } |
| 3553 | |
| 3554 | static int |
| 3555 | qeth_mpc_initialize(struct qeth_card *card) |
| 3556 | { |
| 3557 | int rc; |
| 3558 | |
| 3559 | QETH_DBF_TEXT(setup,2,"mpcinit"); |
| 3560 | |
| 3561 | if ((rc = qeth_issue_next_read(card))){ |
| 3562 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 3563 | return rc; |
| 3564 | } |
| 3565 | if ((rc = qeth_cm_enable(card))){ |
| 3566 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3567 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | } |
| 3569 | if ((rc = qeth_cm_setup(card))){ |
| 3570 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3571 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | } |
| 3573 | if ((rc = qeth_ulp_enable(card))){ |
| 3574 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3575 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | } |
| 3577 | if ((rc = qeth_ulp_setup(card))){ |
| 3578 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3579 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | } |
| 3581 | if ((rc = qeth_alloc_qdio_buffers(card))){ |
| 3582 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 3583 | goto out_qdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | } |
| 3585 | if ((rc = qeth_qdio_establish(card))){ |
| 3586 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 3587 | qeth_free_qdio_buffers(card); |
| 3588 | goto out_qdio; |
| 3589 | } |
| 3590 | if ((rc = qeth_qdio_activate(card))){ |
| 3591 | QETH_DBF_TEXT_(setup, 2, "7err%d", rc); |
| 3592 | goto out_qdio; |
| 3593 | } |
| 3594 | if ((rc = qeth_dm_act(card))){ |
| 3595 | QETH_DBF_TEXT_(setup, 2, "8err%d", rc); |
| 3596 | goto out_qdio; |
| 3597 | } |
| 3598 | |
| 3599 | return 0; |
| 3600 | out_qdio: |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3601 | qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | return rc; |
| 3603 | } |
| 3604 | |
| 3605 | static struct net_device * |
| 3606 | qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype) |
| 3607 | { |
| 3608 | struct net_device *dev = NULL; |
| 3609 | |
| 3610 | switch (type) { |
| 3611 | case QETH_CARD_TYPE_OSAE: |
| 3612 | switch (linktype) { |
| 3613 | case QETH_LINK_TYPE_LANE_TR: |
| 3614 | case QETH_LINK_TYPE_HSTR: |
| 3615 | #ifdef CONFIG_TR |
| 3616 | dev = alloc_trdev(0); |
| 3617 | #endif /* CONFIG_TR */ |
| 3618 | break; |
| 3619 | default: |
| 3620 | dev = alloc_etherdev(0); |
| 3621 | } |
| 3622 | break; |
| 3623 | case QETH_CARD_TYPE_IQD: |
| 3624 | dev = alloc_netdev(0, "hsi%d", ether_setup); |
| 3625 | break; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3626 | case QETH_CARD_TYPE_OSN: |
| 3627 | dev = alloc_netdev(0, "osn%d", ether_setup); |
| 3628 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | default: |
| 3630 | dev = alloc_etherdev(0); |
| 3631 | } |
| 3632 | return dev; |
| 3633 | } |
| 3634 | |
| 3635 | /*hard_header fake function; used in case fake_ll is set */ |
| 3636 | static int |
| 3637 | qeth_fake_header(struct sk_buff *skb, struct net_device *dev, |
| 3638 | unsigned short type, void *daddr, void *saddr, |
| 3639 | unsigned len) |
| 3640 | { |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 3641 | if(dev->type == ARPHRD_IEEE802_TR){ |
| 3642 | struct trh_hdr *hdr; |
| 3643 | hdr = (struct trh_hdr *)skb_push(skb, QETH_FAKE_LL_LEN_TR); |
| 3644 | memcpy(hdr->saddr, dev->dev_addr, TR_ALEN); |
| 3645 | memcpy(hdr->daddr, "FAKELL", TR_ALEN); |
| 3646 | return QETH_FAKE_LL_LEN_TR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 3648 | } else { |
| 3649 | struct ethhdr *hdr; |
| 3650 | hdr = (struct ethhdr *)skb_push(skb, QETH_FAKE_LL_LEN_ETH); |
| 3651 | memcpy(hdr->h_source, dev->dev_addr, ETH_ALEN); |
| 3652 | memcpy(hdr->h_dest, "FAKELL", ETH_ALEN); |
| 3653 | if (type != ETH_P_802_3) |
| 3654 | hdr->h_proto = htons(type); |
| 3655 | else |
| 3656 | hdr->h_proto = htons(len); |
| 3657 | return QETH_FAKE_LL_LEN_ETH; |
| 3658 | |
| 3659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | static inline int |
| 3663 | qeth_send_packet(struct qeth_card *, struct sk_buff *); |
| 3664 | |
| 3665 | static int |
| 3666 | qeth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 3667 | { |
| 3668 | int rc; |
| 3669 | struct qeth_card *card; |
| 3670 | |
| 3671 | QETH_DBF_TEXT(trace, 6, "hrdstxmi"); |
| 3672 | card = (struct qeth_card *)dev->priv; |
| 3673 | if (skb==NULL) { |
| 3674 | card->stats.tx_dropped++; |
| 3675 | card->stats.tx_errors++; |
| 3676 | /* return OK; otherwise ksoftirqd goes to 100% */ |
| 3677 | return NETDEV_TX_OK; |
| 3678 | } |
| 3679 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 3680 | card->stats.tx_dropped++; |
| 3681 | card->stats.tx_errors++; |
| 3682 | card->stats.tx_carrier_errors++; |
| 3683 | dev_kfree_skb_any(skb); |
| 3684 | /* return OK; otherwise ksoftirqd goes to 100% */ |
| 3685 | return NETDEV_TX_OK; |
| 3686 | } |
| 3687 | #ifdef CONFIG_QETH_PERF_STATS |
| 3688 | card->perf_stats.outbound_cnt++; |
| 3689 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 3690 | #endif |
| 3691 | netif_stop_queue(dev); |
| 3692 | if ((rc = qeth_send_packet(card, skb))) { |
| 3693 | if (rc == -EBUSY) { |
| 3694 | return NETDEV_TX_BUSY; |
| 3695 | } else { |
| 3696 | card->stats.tx_errors++; |
| 3697 | card->stats.tx_dropped++; |
| 3698 | dev_kfree_skb_any(skb); |
| 3699 | /*set to OK; otherwise ksoftirqd goes to 100% */ |
| 3700 | rc = NETDEV_TX_OK; |
| 3701 | } |
| 3702 | } |
| 3703 | netif_wake_queue(dev); |
| 3704 | #ifdef CONFIG_QETH_PERF_STATS |
| 3705 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 3706 | card->perf_stats.outbound_start_time; |
| 3707 | #endif |
| 3708 | return rc; |
| 3709 | } |
| 3710 | |
| 3711 | static int |
| 3712 | qeth_verify_vlan_dev(struct net_device *dev, struct qeth_card *card) |
| 3713 | { |
| 3714 | int rc = 0; |
| 3715 | #ifdef CONFIG_QETH_VLAN |
| 3716 | struct vlan_group *vg; |
| 3717 | int i; |
| 3718 | |
| 3719 | if (!(vg = card->vlangrp)) |
| 3720 | return rc; |
| 3721 | |
| 3722 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++){ |
| 3723 | if (vg->vlan_devices[i] == dev){ |
| 3724 | rc = QETH_VLAN_CARD; |
| 3725 | break; |
| 3726 | } |
| 3727 | } |
Frank Pavlic | 6c6b3e7 | 2005-12-13 08:21:47 +0100 | [diff] [blame] | 3728 | if (rc && !(VLAN_DEV_INFO(dev)->real_dev->priv == (void *)card)) |
| 3729 | return 0; |
| 3730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | #endif |
| 3732 | return rc; |
| 3733 | } |
| 3734 | |
| 3735 | static int |
| 3736 | qeth_verify_dev(struct net_device *dev) |
| 3737 | { |
| 3738 | struct qeth_card *card; |
| 3739 | unsigned long flags; |
| 3740 | int rc = 0; |
| 3741 | |
| 3742 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 3743 | list_for_each_entry(card, &qeth_card_list.list, list){ |
| 3744 | if (card->dev == dev){ |
| 3745 | rc = QETH_REAL_CARD; |
| 3746 | break; |
| 3747 | } |
| 3748 | rc = qeth_verify_vlan_dev(dev, card); |
| 3749 | if (rc) |
| 3750 | break; |
| 3751 | } |
| 3752 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 3753 | |
| 3754 | return rc; |
| 3755 | } |
| 3756 | |
| 3757 | static struct qeth_card * |
| 3758 | qeth_get_card_from_dev(struct net_device *dev) |
| 3759 | { |
| 3760 | struct qeth_card *card = NULL; |
| 3761 | int rc; |
| 3762 | |
| 3763 | rc = qeth_verify_dev(dev); |
| 3764 | if (rc == QETH_REAL_CARD) |
| 3765 | card = (struct qeth_card *)dev->priv; |
| 3766 | else if (rc == QETH_VLAN_CARD) |
| 3767 | card = (struct qeth_card *) |
| 3768 | VLAN_DEV_INFO(dev)->real_dev->priv; |
| 3769 | |
| 3770 | QETH_DBF_TEXT_(trace, 4, "%d", rc); |
| 3771 | return card ; |
| 3772 | } |
| 3773 | |
| 3774 | static void |
| 3775 | qeth_tx_timeout(struct net_device *dev) |
| 3776 | { |
| 3777 | struct qeth_card *card; |
| 3778 | |
| 3779 | card = (struct qeth_card *) dev->priv; |
| 3780 | card->stats.tx_errors++; |
| 3781 | qeth_schedule_recovery(card); |
| 3782 | } |
| 3783 | |
| 3784 | static int |
| 3785 | qeth_open(struct net_device *dev) |
| 3786 | { |
| 3787 | struct qeth_card *card; |
| 3788 | |
| 3789 | QETH_DBF_TEXT(trace, 4, "qethopen"); |
| 3790 | |
| 3791 | card = (struct qeth_card *) dev->priv; |
| 3792 | |
| 3793 | if (card->state != CARD_STATE_SOFTSETUP) |
| 3794 | return -ENODEV; |
| 3795 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3796 | if ( (card->info.type != QETH_CARD_TYPE_OSN) && |
| 3797 | (card->options.layer2) && |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 3798 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | QETH_DBF_TEXT(trace,4,"nomacadr"); |
| 3800 | return -EPERM; |
| 3801 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | card->data.state = CH_STATE_UP; |
| 3803 | card->state = CARD_STATE_UP; |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 3804 | card->dev->flags |= IFF_UP; |
| 3805 | netif_start_queue(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 3806 | |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 3807 | if (!card->lan_online && netif_carrier_ok(dev)) |
| 3808 | netif_carrier_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | return 0; |
| 3810 | } |
| 3811 | |
| 3812 | static int |
| 3813 | qeth_stop(struct net_device *dev) |
| 3814 | { |
| 3815 | struct qeth_card *card; |
| 3816 | |
| 3817 | QETH_DBF_TEXT(trace, 4, "qethstop"); |
| 3818 | |
| 3819 | card = (struct qeth_card *) dev->priv; |
| 3820 | |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 3821 | netif_tx_disable(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | card->dev->flags &= ~IFF_UP; |
| 3823 | if (card->state == CARD_STATE_UP) |
| 3824 | card->state = CARD_STATE_SOFTSETUP; |
| 3825 | return 0; |
| 3826 | } |
| 3827 | |
| 3828 | static inline int |
| 3829 | qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb) |
| 3830 | { |
| 3831 | int cast_type = RTN_UNSPEC; |
| 3832 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 3833 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 3834 | return cast_type; |
| 3835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | if (skb->dst && skb->dst->neighbour){ |
| 3837 | cast_type = skb->dst->neighbour->type; |
| 3838 | if ((cast_type == RTN_BROADCAST) || |
| 3839 | (cast_type == RTN_MULTICAST) || |
| 3840 | (cast_type == RTN_ANYCAST)) |
| 3841 | return cast_type; |
| 3842 | else |
| 3843 | return RTN_UNSPEC; |
| 3844 | } |
| 3845 | /* try something else */ |
| 3846 | if (skb->protocol == ETH_P_IPV6) |
| 3847 | return (skb->nh.raw[24] == 0xff) ? RTN_MULTICAST : 0; |
| 3848 | else if (skb->protocol == ETH_P_IP) |
| 3849 | return ((skb->nh.raw[16] & 0xf0) == 0xe0) ? RTN_MULTICAST : 0; |
| 3850 | /* ... */ |
| 3851 | if (!memcmp(skb->data, skb->dev->broadcast, 6)) |
| 3852 | return RTN_BROADCAST; |
| 3853 | else { |
| 3854 | u16 hdr_mac; |
| 3855 | |
| 3856 | hdr_mac = *((u16 *)skb->data); |
| 3857 | /* tr multicast? */ |
| 3858 | switch (card->info.link_type) { |
| 3859 | case QETH_LINK_TYPE_HSTR: |
| 3860 | case QETH_LINK_TYPE_LANE_TR: |
| 3861 | if ((hdr_mac == QETH_TR_MAC_NC) || |
| 3862 | (hdr_mac == QETH_TR_MAC_C)) |
| 3863 | return RTN_MULTICAST; |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 3864 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | /* eth or so multicast? */ |
| 3866 | default: |
| 3867 | if ((hdr_mac == QETH_ETH_MAC_V4) || |
| 3868 | (hdr_mac == QETH_ETH_MAC_V6)) |
| 3869 | return RTN_MULTICAST; |
| 3870 | } |
| 3871 | } |
| 3872 | return cast_type; |
| 3873 | } |
| 3874 | |
| 3875 | static inline int |
| 3876 | qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb, |
| 3877 | int ipv, int cast_type) |
| 3878 | { |
| 3879 | if (!ipv && (card->info.type == QETH_CARD_TYPE_OSAE)) |
| 3880 | return card->qdio.default_out_queue; |
| 3881 | switch (card->qdio.no_out_queues) { |
| 3882 | case 4: |
| 3883 | if (cast_type && card->info.is_multicast_different) |
| 3884 | return card->info.is_multicast_different & |
| 3885 | (card->qdio.no_out_queues - 1); |
| 3886 | if (card->qdio.do_prio_queueing && (ipv == 4)) { |
| 3887 | if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_TOS){ |
| 3888 | if (skb->nh.iph->tos & IP_TOS_NOTIMPORTANT) |
| 3889 | return 3; |
| 3890 | if (skb->nh.iph->tos & IP_TOS_HIGHRELIABILITY) |
| 3891 | return 2; |
| 3892 | if (skb->nh.iph->tos & IP_TOS_HIGHTHROUGHPUT) |
| 3893 | return 1; |
| 3894 | if (skb->nh.iph->tos & IP_TOS_LOWDELAY) |
| 3895 | return 0; |
| 3896 | } |
| 3897 | if (card->qdio.do_prio_queueing==QETH_PRIO_Q_ING_PREC) |
| 3898 | return 3 - (skb->nh.iph->tos >> 6); |
| 3899 | } else if (card->qdio.do_prio_queueing && (ipv == 6)) { |
| 3900 | /* TODO: IPv6!!! */ |
| 3901 | } |
| 3902 | return card->qdio.default_out_queue; |
| 3903 | case 1: /* fallthrough for single-out-queue 1920-device */ |
| 3904 | default: |
| 3905 | return card->qdio.default_out_queue; |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | static inline int |
| 3910 | qeth_get_ip_version(struct sk_buff *skb) |
| 3911 | { |
| 3912 | switch (skb->protocol) { |
| 3913 | case ETH_P_IPV6: |
| 3914 | return 6; |
| 3915 | case ETH_P_IP: |
| 3916 | return 4; |
| 3917 | default: |
| 3918 | return 0; |
| 3919 | } |
| 3920 | } |
| 3921 | |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 3922 | static inline struct qeth_hdr * |
| 3923 | __qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, int ipv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | #ifdef CONFIG_QETH_VLAN |
| 3926 | u16 *tag; |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 3927 | if (card->vlangrp && vlan_tx_tag_present(skb) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | ((ipv == 6) || card->options.layer2) ) { |
| 3929 | /* |
| 3930 | * Move the mac addresses (6 bytes src, 6 bytes dest) |
| 3931 | * to the beginning of the new header. We are using three |
| 3932 | * memcpys instead of one memmove to save cycles. |
| 3933 | */ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 3934 | skb_push(skb, VLAN_HLEN); |
| 3935 | memcpy(skb->data, skb->data + 4, 4); |
| 3936 | memcpy(skb->data + 4, skb->data + 8, 4); |
| 3937 | memcpy(skb->data + 8, skb->data + 12, 4); |
| 3938 | tag = (u16 *)(skb->data + 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | /* |
| 3940 | * first two bytes = ETH_P_8021Q (0x8100) |
| 3941 | * second two bytes = VLANID |
| 3942 | */ |
| 3943 | *tag = __constant_htons(ETH_P_8021Q); |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 3944 | *(tag + 1) = htons(vlan_tx_tag_get(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | } |
| 3946 | #endif |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 3947 | return ((struct qeth_hdr *) |
| 3948 | qeth_push_skb(card, skb, sizeof(struct qeth_hdr))); |
| 3949 | } |
| 3950 | |
| 3951 | static inline void |
| 3952 | __qeth_free_new_skb(struct sk_buff *orig_skb, struct sk_buff *new_skb) |
| 3953 | { |
| 3954 | if (orig_skb != new_skb) |
| 3955 | dev_kfree_skb_any(new_skb); |
| 3956 | } |
| 3957 | |
| 3958 | static inline struct sk_buff * |
| 3959 | qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb, |
| 3960 | struct qeth_hdr **hdr, int ipv) |
| 3961 | { |
| 3962 | struct sk_buff *new_skb; |
| 3963 | |
| 3964 | QETH_DBF_TEXT(trace, 6, "prepskb"); |
| 3965 | |
| 3966 | new_skb = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr)); |
| 3967 | if (new_skb == NULL) |
| 3968 | return NULL; |
| 3969 | *hdr = __qeth_prepare_skb(card, new_skb, ipv); |
| 3970 | if (*hdr == NULL) { |
| 3971 | __qeth_free_new_skb(skb, new_skb); |
| 3972 | return NULL; |
| 3973 | } |
| 3974 | return new_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | static inline u8 |
| 3978 | qeth_get_qeth_hdr_flags4(int cast_type) |
| 3979 | { |
| 3980 | if (cast_type == RTN_MULTICAST) |
| 3981 | return QETH_CAST_MULTICAST; |
| 3982 | if (cast_type == RTN_BROADCAST) |
| 3983 | return QETH_CAST_BROADCAST; |
| 3984 | return QETH_CAST_UNICAST; |
| 3985 | } |
| 3986 | |
| 3987 | static inline u8 |
| 3988 | qeth_get_qeth_hdr_flags6(int cast_type) |
| 3989 | { |
| 3990 | u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6; |
| 3991 | if (cast_type == RTN_MULTICAST) |
| 3992 | return ct | QETH_CAST_MULTICAST; |
| 3993 | if (cast_type == RTN_ANYCAST) |
| 3994 | return ct | QETH_CAST_ANYCAST; |
| 3995 | if (cast_type == RTN_BROADCAST) |
| 3996 | return ct | QETH_CAST_BROADCAST; |
| 3997 | return ct | QETH_CAST_UNICAST; |
| 3998 | } |
| 3999 | |
| 4000 | static inline void |
| 4001 | qeth_layer2_get_packet_type(struct qeth_card *card, struct qeth_hdr *hdr, |
| 4002 | struct sk_buff *skb) |
| 4003 | { |
| 4004 | __u16 hdr_mac; |
| 4005 | |
| 4006 | if (!memcmp(skb->data+QETH_HEADER_SIZE, |
| 4007 | skb->dev->broadcast,6)) { /* broadcast? */ |
| 4008 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4009 | QETH_LAYER2_FLAG_BROADCAST << 8; |
| 4010 | return; |
| 4011 | } |
| 4012 | hdr_mac=*((__u16*)skb->data); |
| 4013 | /* tr multicast? */ |
| 4014 | switch (card->info.link_type) { |
| 4015 | case QETH_LINK_TYPE_HSTR: |
| 4016 | case QETH_LINK_TYPE_LANE_TR: |
| 4017 | if ((hdr_mac == QETH_TR_MAC_NC) || |
| 4018 | (hdr_mac == QETH_TR_MAC_C) ) |
| 4019 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4020 | QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4021 | else |
| 4022 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4023 | QETH_LAYER2_FLAG_UNICAST << 8; |
| 4024 | break; |
| 4025 | /* eth or so multicast? */ |
| 4026 | default: |
| 4027 | if ( (hdr_mac==QETH_ETH_MAC_V4) || |
| 4028 | (hdr_mac==QETH_ETH_MAC_V6) ) |
| 4029 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4030 | QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4031 | else |
| 4032 | *(__u32 *)hdr->hdr.l2.flags |= |
| 4033 | QETH_LAYER2_FLAG_UNICAST << 8; |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | static inline void |
| 4038 | qeth_layer2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 4039 | struct sk_buff *skb, int cast_type) |
| 4040 | { |
| 4041 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 4042 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
| 4043 | |
| 4044 | /* set byte 0 to "0x02" and byte 3 to casting flags */ |
| 4045 | if (cast_type==RTN_MULTICAST) |
| 4046 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_MULTICAST << 8; |
| 4047 | else if (cast_type==RTN_BROADCAST) |
| 4048 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_BROADCAST << 8; |
| 4049 | else |
| 4050 | qeth_layer2_get_packet_type(card, hdr, skb); |
| 4051 | |
| 4052 | hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE; |
| 4053 | #ifdef CONFIG_QETH_VLAN |
| 4054 | /* VSWITCH relies on the VLAN |
| 4055 | * information to be present in |
| 4056 | * the QDIO header */ |
| 4057 | if ((card->vlangrp != NULL) && |
| 4058 | vlan_tx_tag_present(skb)) { |
| 4059 | *(__u32 *)hdr->hdr.l2.flags |= QETH_LAYER2_FLAG_VLAN << 8; |
| 4060 | hdr->hdr.l2.vlan_id = vlan_tx_tag_get(skb); |
| 4061 | } |
| 4062 | #endif |
| 4063 | } |
| 4064 | |
| 4065 | void |
| 4066 | qeth_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 4067 | struct sk_buff *skb, int ipv, int cast_type) |
| 4068 | { |
| 4069 | QETH_DBF_TEXT(trace, 6, "fillhdr"); |
| 4070 | |
| 4071 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 4072 | if (card->options.layer2) { |
| 4073 | qeth_layer2_fill_header(card, hdr, skb, cast_type); |
| 4074 | return; |
| 4075 | } |
| 4076 | hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; |
| 4077 | hdr->hdr.l3.ext_flags = 0; |
| 4078 | #ifdef CONFIG_QETH_VLAN |
| 4079 | /* |
| 4080 | * before we're going to overwrite this location with next hop ip. |
| 4081 | * v6 uses passthrough, v4 sets the tag in the QDIO header. |
| 4082 | */ |
| 4083 | if (card->vlangrp && vlan_tx_tag_present(skb)) { |
| 4084 | hdr->hdr.l3.ext_flags = (ipv == 4) ? |
| 4085 | QETH_HDR_EXT_VLAN_FRAME : |
| 4086 | QETH_HDR_EXT_INCLUDE_VLAN_TAG; |
| 4087 | hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb); |
| 4088 | } |
| 4089 | #endif /* CONFIG_QETH_VLAN */ |
| 4090 | hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr); |
| 4091 | if (ipv == 4) { /* IPv4 */ |
| 4092 | hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags4(cast_type); |
| 4093 | memset(hdr->hdr.l3.dest_addr, 0, 12); |
| 4094 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 4095 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = |
| 4096 | *((u32 *) skb->dst->neighbour->primary_key); |
| 4097 | } else { |
| 4098 | /* fill in destination address used in ip header */ |
| 4099 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = skb->nh.iph->daddr; |
| 4100 | } |
| 4101 | } else if (ipv == 6) { /* IPv6 or passthru */ |
| 4102 | hdr->hdr.l3.flags = qeth_get_qeth_hdr_flags6(cast_type); |
| 4103 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 4104 | memcpy(hdr->hdr.l3.dest_addr, |
| 4105 | skb->dst->neighbour->primary_key, 16); |
| 4106 | } else { |
| 4107 | /* fill in destination address used in ip header */ |
| 4108 | memcpy(hdr->hdr.l3.dest_addr, &skb->nh.ipv6h->daddr, 16); |
| 4109 | } |
| 4110 | } else { /* passthrough */ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4111 | if((skb->dev->type == ARPHRD_IEEE802_TR) && |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 4112 | !memcmp(skb->data + sizeof(struct qeth_hdr) + |
Frank Pavlic | 9a45581 | 2005-05-12 20:38:28 +0200 | [diff] [blame] | 4113 | sizeof(__u16), skb->dev->broadcast, 6)) { |
| 4114 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 4115 | QETH_HDR_PASSTHRU; |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4116 | } else if (!memcmp(skb->data + sizeof(struct qeth_hdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | skb->dev->broadcast, 6)) { /* broadcast? */ |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4118 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 4119 | QETH_HDR_PASSTHRU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | } else { |
| 4121 | hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ? |
| 4122 | QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU : |
| 4123 | QETH_CAST_UNICAST | QETH_HDR_PASSTHRU; |
| 4124 | } |
| 4125 | } |
| 4126 | } |
| 4127 | |
| 4128 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer, |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4130 | int is_tso, int *next_element_to_fill) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | { |
| 4132 | int length = skb->len; |
| 4133 | int length_here; |
| 4134 | int element; |
| 4135 | char *data; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4136 | int first_lap ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | |
| 4138 | element = *next_element_to_fill; |
| 4139 | data = skb->data; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4140 | first_lap = (is_tso == 0 ? 1 : 0); |
| 4141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | while (length > 0) { |
| 4143 | /* length_here is the remaining amount of data in this page */ |
| 4144 | length_here = PAGE_SIZE - ((unsigned long) data % PAGE_SIZE); |
| 4145 | if (length < length_here) |
| 4146 | length_here = length; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | buffer->element[element].addr = data; |
| 4149 | buffer->element[element].length = length_here; |
| 4150 | length -= length_here; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4151 | if (!length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | if (first_lap) |
| 4153 | buffer->element[element].flags = 0; |
| 4154 | else |
| 4155 | buffer->element[element].flags = |
| 4156 | SBAL_FLAGS_LAST_FRAG; |
| 4157 | } else { |
| 4158 | if (first_lap) |
| 4159 | buffer->element[element].flags = |
| 4160 | SBAL_FLAGS_FIRST_FRAG; |
| 4161 | else |
| 4162 | buffer->element[element].flags = |
| 4163 | SBAL_FLAGS_MIDDLE_FRAG; |
| 4164 | } |
| 4165 | data += length_here; |
| 4166 | element++; |
| 4167 | first_lap = 0; |
| 4168 | } |
| 4169 | *next_element_to_fill = element; |
| 4170 | } |
| 4171 | |
| 4172 | static inline int |
| 4173 | qeth_fill_buffer(struct qeth_qdio_out_q *queue, |
| 4174 | struct qeth_qdio_out_buffer *buf, |
| 4175 | struct sk_buff *skb) |
| 4176 | { |
| 4177 | struct qdio_buffer *buffer; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4178 | struct qeth_hdr_tso *hdr; |
| 4179 | int flush_cnt = 0, hdr_len, large_send = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | |
| 4181 | QETH_DBF_TEXT(trace, 6, "qdfillbf"); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | buffer = buf->buffer; |
| 4184 | atomic_inc(&skb->users); |
| 4185 | skb_queue_tail(&buf->skb_list, skb); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4186 | |
| 4187 | hdr = (struct qeth_hdr_tso *) skb->data; |
| 4188 | /*check first on TSO ....*/ |
| 4189 | if (hdr->hdr.hdr.l3.id == QETH_HEADER_TYPE_TSO) { |
| 4190 | int element = buf->next_element_to_fill; |
| 4191 | |
| 4192 | hdr_len = sizeof(struct qeth_hdr_tso) + hdr->ext.dg_hdr_len; |
| 4193 | /*fill first buffer entry only with header information */ |
| 4194 | buffer->element[element].addr = skb->data; |
| 4195 | buffer->element[element].length = hdr_len; |
| 4196 | buffer->element[element].flags = SBAL_FLAGS_FIRST_FRAG; |
| 4197 | buf->next_element_to_fill++; |
| 4198 | skb->data += hdr_len; |
| 4199 | skb->len -= hdr_len; |
| 4200 | large_send = 1; |
| 4201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | if (skb_shinfo(skb)->nr_frags == 0) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4203 | __qeth_fill_buffer(skb, buffer, large_send, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | (int *)&buf->next_element_to_fill); |
| 4205 | else |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4206 | __qeth_fill_buffer_frag(skb, buffer, large_send, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | (int *)&buf->next_element_to_fill); |
| 4208 | |
| 4209 | if (!queue->do_pack) { |
| 4210 | QETH_DBF_TEXT(trace, 6, "fillbfnp"); |
| 4211 | /* set state to PRIMED -> will be flushed */ |
| 4212 | atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED); |
| 4213 | flush_cnt = 1; |
| 4214 | } else { |
| 4215 | QETH_DBF_TEXT(trace, 6, "fillbfpa"); |
| 4216 | #ifdef CONFIG_QETH_PERF_STATS |
| 4217 | queue->card->perf_stats.skbs_sent_pack++; |
| 4218 | #endif |
| 4219 | if (buf->next_element_to_fill >= |
| 4220 | QETH_MAX_BUFFER_ELEMENTS(queue->card)) { |
| 4221 | /* |
| 4222 | * packed buffer if full -> set state PRIMED |
| 4223 | * -> will be flushed |
| 4224 | */ |
| 4225 | atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED); |
| 4226 | flush_cnt = 1; |
| 4227 | } |
| 4228 | } |
| 4229 | return flush_cnt; |
| 4230 | } |
| 4231 | |
| 4232 | static inline int |
| 4233 | qeth_do_send_packet_fast(struct qeth_card *card, struct qeth_qdio_out_q *queue, |
| 4234 | struct sk_buff *skb, struct qeth_hdr *hdr, |
| 4235 | int elements_needed, |
| 4236 | struct qeth_eddp_context *ctx) |
| 4237 | { |
| 4238 | struct qeth_qdio_out_buffer *buffer; |
| 4239 | int buffers_needed = 0; |
| 4240 | int flush_cnt = 0; |
| 4241 | int index; |
| 4242 | |
| 4243 | QETH_DBF_TEXT(trace, 6, "dosndpfa"); |
| 4244 | |
| 4245 | /* spin until we get the queue ... */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 4246 | while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, |
| 4247 | QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | /* ... now we've got the queue */ |
| 4249 | index = queue->next_buf_to_fill; |
| 4250 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4251 | /* |
| 4252 | * check if buffer is empty to make sure that we do not 'overtake' |
| 4253 | * ourselves and try to fill a buffer that is already primed |
| 4254 | */ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4255 | if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) |
| 4256 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | if (ctx == NULL) |
| 4258 | queue->next_buf_to_fill = (queue->next_buf_to_fill + 1) % |
| 4259 | QDIO_MAX_BUFFERS_PER_Q; |
| 4260 | else { |
| 4261 | buffers_needed = qeth_eddp_check_buffers_for_context(queue,ctx); |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4262 | if (buffers_needed < 0) |
| 4263 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | queue->next_buf_to_fill = |
| 4265 | (queue->next_buf_to_fill + buffers_needed) % |
| 4266 | QDIO_MAX_BUFFERS_PER_Q; |
| 4267 | } |
| 4268 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4269 | if (ctx == NULL) { |
| 4270 | qeth_fill_buffer(queue, buffer, skb); |
| 4271 | qeth_flush_buffers(queue, 0, index, 1); |
| 4272 | } else { |
| 4273 | flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index); |
| 4274 | WARN_ON(buffers_needed != flush_cnt); |
| 4275 | qeth_flush_buffers(queue, 0, index, flush_cnt); |
| 4276 | } |
| 4277 | return 0; |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4278 | out: |
| 4279 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4280 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | static inline int |
| 4284 | qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue, |
| 4285 | struct sk_buff *skb, struct qeth_hdr *hdr, |
| 4286 | int elements_needed, struct qeth_eddp_context *ctx) |
| 4287 | { |
| 4288 | struct qeth_qdio_out_buffer *buffer; |
| 4289 | int start_index; |
| 4290 | int flush_count = 0; |
| 4291 | int do_pack = 0; |
| 4292 | int tmp; |
| 4293 | int rc = 0; |
| 4294 | |
| 4295 | QETH_DBF_TEXT(trace, 6, "dosndpkt"); |
| 4296 | |
| 4297 | /* spin until we get the queue ... */ |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 4298 | while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, |
| 4299 | QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | start_index = queue->next_buf_to_fill; |
| 4301 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4302 | /* |
| 4303 | * check if buffer is empty to make sure that we do not 'overtake' |
| 4304 | * ourselves and try to fill a buffer that is already primed |
| 4305 | */ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4306 | if (atomic_read(&buffer->state) != QETH_QDIO_BUF_EMPTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4308 | return -EBUSY; |
| 4309 | } |
| 4310 | /* check if we need to switch packing state of this queue */ |
| 4311 | qeth_switch_to_packing_if_needed(queue); |
| 4312 | if (queue->do_pack){ |
| 4313 | do_pack = 1; |
| 4314 | if (ctx == NULL) { |
| 4315 | /* does packet fit in current buffer? */ |
| 4316 | if((QETH_MAX_BUFFER_ELEMENTS(card) - |
| 4317 | buffer->next_element_to_fill) < elements_needed){ |
| 4318 | /* ... no -> set state PRIMED */ |
| 4319 | atomic_set(&buffer->state,QETH_QDIO_BUF_PRIMED); |
| 4320 | flush_count++; |
| 4321 | queue->next_buf_to_fill = |
| 4322 | (queue->next_buf_to_fill + 1) % |
| 4323 | QDIO_MAX_BUFFERS_PER_Q; |
| 4324 | buffer = &queue->bufs[queue->next_buf_to_fill]; |
| 4325 | /* we did a step forward, so check buffer state |
| 4326 | * again */ |
| 4327 | if (atomic_read(&buffer->state) != |
| 4328 | QETH_QDIO_BUF_EMPTY){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | qeth_flush_buffers(queue, 0, start_index, flush_count); |
| 4330 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
| 4331 | return -EBUSY; |
| 4332 | } |
| 4333 | } |
| 4334 | } else { |
| 4335 | /* check if we have enough elements (including following |
| 4336 | * free buffers) to handle eddp context */ |
| 4337 | if (qeth_eddp_check_buffers_for_context(queue,ctx) < 0){ |
| 4338 | printk("eddp tx_dropped 1\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | rc = -EBUSY; |
| 4340 | goto out; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | if (ctx == NULL) |
| 4345 | tmp = qeth_fill_buffer(queue, buffer, skb); |
| 4346 | else { |
| 4347 | tmp = qeth_eddp_fill_buffer(queue,ctx,queue->next_buf_to_fill); |
| 4348 | if (tmp < 0) { |
| 4349 | printk("eddp tx_dropped 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4397 | if (skb_shinfo(skb)->nr_frags > 0) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4398 | elements_needed = (skb_shinfo(skb)->nr_frags + 1); |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4399 | if (elements_needed == 0) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4400 | elements_needed = 1 + (((((unsigned long) hdr) % PAGE_SIZE) |
| 4401 | + skb->len) >> PAGE_SHIFT); |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4402 | if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)){ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4403 | PRINT_ERR("Invalid size of IP packet " |
| 4404 | "(Number=%d / Length=%d). Discarded.\n", |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4405 | (elements_needed+elems), skb->len); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4406 | return 0; |
| 4407 | } |
| 4408 | return elements_needed; |
| 4409 | } |
| 4410 | |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4411 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 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 |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4427 | struct sk_buff *new_skb, *new_skb2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | int rc; |
| 4429 | |
| 4430 | QETH_DBF_TEXT(trace, 6, "sendpkt"); |
| 4431 | |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4432 | new_skb = skb; |
| 4433 | if ((card->info.type == QETH_CARD_TYPE_OSN) && |
| 4434 | (skb->protocol == htons(ETH_P_IPV6))) |
| 4435 | return -EPERM; |
| 4436 | cast_type = qeth_get_cast_type(card, skb); |
| 4437 | if ((cast_type == RTN_BROADCAST) && |
| 4438 | (card->info.broadcast_capable == 0)) |
| 4439 | return -EPERM; |
| 4440 | queue = card->qdio.out_qs |
| 4441 | [qeth_get_priority_queue(card, skb, ipv, cast_type)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | if (!card->options.layer2) { |
| 4443 | ipv = qeth_get_ip_version(skb); |
| 4444 | if ((card->dev->hard_header == qeth_fake_header) && ipv) { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4445 | new_skb = qeth_pskb_unshare(skb, GFP_ATOMIC); |
| 4446 | if (!new_skb) |
| 4447 | return -ENOMEM; |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4448 | if(card->dev->type == ARPHRD_IEEE802_TR){ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4449 | skb_pull(new_skb, QETH_FAKE_LL_LEN_TR); |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4450 | } else { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4451 | skb_pull(new_skb, QETH_FAKE_LL_LEN_ETH); |
Frank Pavlic | e23dd9c | 2005-05-12 20:38:11 +0200 | [diff] [blame] | 4452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | } |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 4455 | if (skb_is_gso(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | large_send = card->options.large_send; |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4457 | /* check on OSN device*/ |
| 4458 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 4459 | hdr = (struct qeth_hdr *)new_skb->data; |
| 4460 | /*are we able to do TSO ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | if ((large_send == QETH_LARGE_SEND_TSO) && |
| 4462 | (cast_type == RTN_UNSPEC)) { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4463 | rc = qeth_tso_prepare_packet(card, new_skb, ipv, cast_type); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4464 | if (rc) { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4465 | __qeth_free_new_skb(skb, new_skb); |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 4466 | return rc; |
| 4467 | } |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4468 | elements_needed++; |
| 4469 | } else if (card->info.type != QETH_CARD_TYPE_OSN) { |
| 4470 | new_skb2 = qeth_prepare_skb(card, new_skb, &hdr, ipv); |
| 4471 | if (!new_skb2) { |
| 4472 | __qeth_free_new_skb(skb, new_skb); |
| 4473 | return -EINVAL; |
| 4474 | } |
| 4475 | if (new_skb != skb) |
| 4476 | __qeth_free_new_skb(new_skb2, new_skb); |
| 4477 | new_skb = new_skb2; |
| 4478 | qeth_fill_header(card, hdr, new_skb, ipv, cast_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | if (large_send == QETH_LARGE_SEND_EDDP) { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4481 | ctx = qeth_eddp_create_context(card, new_skb, hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | if (ctx == NULL) { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4483 | __qeth_free_new_skb(skb, new_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | PRINT_WARN("could not create eddp context\n"); |
| 4485 | return -EINVAL; |
| 4486 | } |
| 4487 | } else { |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4488 | int elems = qeth_get_elements_no(card,(void*) hdr, new_skb, |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4489 | elements_needed); |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4490 | if (!elems) { |
| 4491 | __qeth_free_new_skb(skb, new_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | return -EINVAL; |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4493 | } |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 4494 | elements_needed += elems; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | if (card->info.type != QETH_CARD_TYPE_IQD) |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4498 | rc = qeth_do_send_packet(card, queue, new_skb, hdr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | elements_needed, ctx); |
| 4500 | else |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4501 | rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | elements_needed, ctx); |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4503 | if (!rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | card->stats.tx_packets++; |
Frank Pavlic | 95f6b5a | 2006-03-22 16:03:39 +0100 | [diff] [blame] | 4505 | card->stats.tx_bytes += tx_bytes; |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4506 | if (new_skb != skb) |
| 4507 | dev_kfree_skb_any(skb); |
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 | } |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +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 */ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4521 | } else { |
| 4522 | card->stats.tx_dropped++; |
| 4523 | __qeth_free_new_skb(skb, new_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | } |
| 4525 | if (ctx != NULL) { |
| 4526 | /* drop creator's reference */ |
| 4527 | qeth_eddp_put_context(ctx); |
| 4528 | /* free skb; it's not referenced by a buffer */ |
Frank Pavlic | f7b65d7 | 2006-09-15 16:26:19 +0200 | [diff] [blame^] | 4529 | if (!rc) |
| 4530 | dev_kfree_skb_any(new_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | } |
| 4532 | return rc; |
| 4533 | } |
| 4534 | |
| 4535 | static int |
| 4536 | qeth_mdio_read(struct net_device *dev, int phy_id, int regnum) |
| 4537 | { |
| 4538 | struct qeth_card *card = (struct qeth_card *) dev->priv; |
| 4539 | int rc = 0; |
| 4540 | |
| 4541 | switch(regnum){ |
| 4542 | case MII_BMCR: /* Basic mode control register */ |
| 4543 | rc = BMCR_FULLDPLX; |
| 4544 | if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&& |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 4545 | (card->info.link_type != QETH_LINK_TYPE_OSN) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH)) |
| 4547 | rc |= BMCR_SPEED100; |
| 4548 | break; |
| 4549 | case MII_BMSR: /* Basic mode status register */ |
| 4550 | rc = BMSR_ERCAP | BMSR_ANEGCOMPLETE | BMSR_LSTATUS | |
| 4551 | BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | BMSR_100FULL | |
| 4552 | BMSR_100BASE4; |
| 4553 | break; |
| 4554 | case MII_PHYSID1: /* PHYS ID 1 */ |
| 4555 | rc = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 8) | |
| 4556 | dev->dev_addr[2]; |
| 4557 | rc = (rc >> 5) & 0xFFFF; |
| 4558 | break; |
| 4559 | case MII_PHYSID2: /* PHYS ID 2 */ |
| 4560 | rc = (dev->dev_addr[2] << 10) & 0xFFFF; |
| 4561 | break; |
| 4562 | case MII_ADVERTISE: /* Advertisement control reg */ |
| 4563 | rc = ADVERTISE_ALL; |
| 4564 | break; |
| 4565 | case MII_LPA: /* Link partner ability reg */ |
| 4566 | rc = LPA_10HALF | LPA_10FULL | LPA_100HALF | LPA_100FULL | |
| 4567 | LPA_100BASE4 | LPA_LPACK; |
| 4568 | break; |
| 4569 | case MII_EXPANSION: /* Expansion register */ |
| 4570 | break; |
| 4571 | case MII_DCOUNTER: /* disconnect counter */ |
| 4572 | break; |
| 4573 | case MII_FCSCOUNTER: /* false carrier counter */ |
| 4574 | break; |
| 4575 | case MII_NWAYTEST: /* N-way auto-neg test register */ |
| 4576 | break; |
| 4577 | case MII_RERRCOUNTER: /* rx error counter */ |
| 4578 | rc = card->stats.rx_errors; |
| 4579 | break; |
| 4580 | case MII_SREVISION: /* silicon revision */ |
| 4581 | break; |
| 4582 | case MII_RESV1: /* reserved 1 */ |
| 4583 | break; |
| 4584 | case MII_LBRERROR: /* loopback, rx, bypass error */ |
| 4585 | break; |
| 4586 | case MII_PHYADDR: /* physical address */ |
| 4587 | break; |
| 4588 | case MII_RESV2: /* reserved 2 */ |
| 4589 | break; |
| 4590 | case MII_TPISTATUS: /* TPI status for 10mbps */ |
| 4591 | break; |
| 4592 | case MII_NCONFIG: /* network interface config */ |
| 4593 | break; |
| 4594 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | break; |
| 4596 | } |
| 4597 | return rc; |
| 4598 | } |
| 4599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | |
| 4601 | static inline const char * |
| 4602 | qeth_arp_get_error_cause(int *rc) |
| 4603 | { |
| 4604 | switch (*rc) { |
| 4605 | case QETH_IPA_ARP_RC_FAILED: |
| 4606 | *rc = -EIO; |
| 4607 | return "operation failed"; |
| 4608 | case QETH_IPA_ARP_RC_NOTSUPP: |
| 4609 | *rc = -EOPNOTSUPP; |
| 4610 | return "operation not supported"; |
| 4611 | case QETH_IPA_ARP_RC_OUT_OF_RANGE: |
| 4612 | *rc = -EINVAL; |
| 4613 | return "argument out of range"; |
| 4614 | case QETH_IPA_ARP_RC_Q_NOTSUPP: |
| 4615 | *rc = -EOPNOTSUPP; |
| 4616 | return "query operation not supported"; |
| 4617 | case QETH_IPA_ARP_RC_Q_NO_DATA: |
| 4618 | *rc = -ENOENT; |
| 4619 | return "no query data available"; |
| 4620 | default: |
| 4621 | return "unknown error"; |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | static int |
| 4626 | qeth_send_simple_setassparms(struct qeth_card *, enum qeth_ipa_funcs, |
| 4627 | __u16, long); |
| 4628 | |
| 4629 | static int |
| 4630 | qeth_arp_set_no_entries(struct qeth_card *card, int no_entries) |
| 4631 | { |
| 4632 | int tmp; |
| 4633 | int rc; |
| 4634 | |
| 4635 | QETH_DBF_TEXT(trace,3,"arpstnoe"); |
| 4636 | |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 4637 | /* |
| 4638 | * currently GuestLAN only supports the ARP assist function |
| 4639 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES; |
| 4640 | * thus we say EOPNOTSUPP for this ARP function |
| 4641 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | if (card->info.guestlan) |
| 4643 | return -EOPNOTSUPP; |
| 4644 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 4645 | PRINT_WARN("ARP processing not supported " |
| 4646 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4647 | return -EOPNOTSUPP; |
| 4648 | } |
| 4649 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 4650 | IPA_CMD_ASS_ARP_SET_NO_ENTRIES, |
| 4651 | no_entries); |
| 4652 | if (rc) { |
| 4653 | tmp = rc; |
| 4654 | PRINT_WARN("Could not set number of ARP entries on %s: " |
| 4655 | "%s (0x%x/%d)\n", |
| 4656 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 4657 | tmp, tmp); |
| 4658 | } |
| 4659 | return rc; |
| 4660 | } |
| 4661 | |
| 4662 | static inline void |
| 4663 | qeth_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo, |
| 4664 | struct qeth_arp_query_data *qdata, |
| 4665 | int entry_size, int uentry_size) |
| 4666 | { |
| 4667 | char *entry_ptr; |
| 4668 | char *uentry_ptr; |
| 4669 | int i; |
| 4670 | |
| 4671 | entry_ptr = (char *)&qdata->data; |
| 4672 | uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset); |
| 4673 | for (i = 0; i < qdata->no_entries; ++i){ |
| 4674 | /* strip off 32 bytes "media specific information" */ |
| 4675 | memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32); |
| 4676 | entry_ptr += entry_size; |
| 4677 | uentry_ptr += uentry_size; |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | static int |
| 4682 | qeth_arp_query_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 4683 | unsigned long data) |
| 4684 | { |
| 4685 | struct qeth_ipa_cmd *cmd; |
| 4686 | struct qeth_arp_query_data *qdata; |
| 4687 | struct qeth_arp_query_info *qinfo; |
| 4688 | int entry_size; |
| 4689 | int uentry_size; |
| 4690 | int i; |
| 4691 | |
| 4692 | QETH_DBF_TEXT(trace,4,"arpquecb"); |
| 4693 | |
| 4694 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 4695 | cmd = (struct qeth_ipa_cmd *) data; |
| 4696 | if (cmd->hdr.return_code) { |
| 4697 | QETH_DBF_TEXT_(trace,4,"qaer1%i", cmd->hdr.return_code); |
| 4698 | return 0; |
| 4699 | } |
| 4700 | if (cmd->data.setassparms.hdr.return_code) { |
| 4701 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
| 4702 | QETH_DBF_TEXT_(trace,4,"qaer2%i", cmd->hdr.return_code); |
| 4703 | return 0; |
| 4704 | } |
| 4705 | qdata = &cmd->data.setassparms.data.query_arp; |
| 4706 | switch(qdata->reply_bits){ |
| 4707 | case 5: |
| 4708 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5); |
| 4709 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4710 | uentry_size = sizeof(struct qeth_arp_qi_entry5_short); |
| 4711 | break; |
| 4712 | case 7: |
| 4713 | /* fall through to default */ |
| 4714 | default: |
| 4715 | /* tr is the same as eth -> entry7 */ |
| 4716 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7); |
| 4717 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4718 | uentry_size = sizeof(struct qeth_arp_qi_entry7_short); |
| 4719 | break; |
| 4720 | } |
| 4721 | /* check if there is enough room in userspace */ |
| 4722 | if ((qinfo->udata_len - qinfo->udata_offset) < |
| 4723 | qdata->no_entries * uentry_size){ |
| 4724 | QETH_DBF_TEXT_(trace, 4, "qaer3%i", -ENOMEM); |
| 4725 | cmd->hdr.return_code = -ENOMEM; |
| 4726 | PRINT_WARN("query ARP user space buffer is too small for " |
| 4727 | "the returned number of ARP entries. " |
| 4728 | "Aborting query!\n"); |
| 4729 | goto out_error; |
| 4730 | } |
| 4731 | QETH_DBF_TEXT_(trace, 4, "anore%i", |
| 4732 | cmd->data.setassparms.hdr.number_of_replies); |
| 4733 | QETH_DBF_TEXT_(trace, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no); |
| 4734 | QETH_DBF_TEXT_(trace, 4, "anoen%i", qdata->no_entries); |
| 4735 | |
| 4736 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) { |
| 4737 | /* strip off "media specific information" */ |
| 4738 | qeth_copy_arp_entries_stripped(qinfo, qdata, entry_size, |
| 4739 | uentry_size); |
| 4740 | } else |
| 4741 | /*copy entries to user buffer*/ |
| 4742 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4743 | (char *)&qdata->data, qdata->no_entries*uentry_size); |
| 4744 | |
| 4745 | qinfo->no_entries += qdata->no_entries; |
| 4746 | qinfo->udata_offset += (qdata->no_entries*uentry_size); |
| 4747 | /* check if all replies received ... */ |
| 4748 | if (cmd->data.setassparms.hdr.seq_no < |
| 4749 | cmd->data.setassparms.hdr.number_of_replies) |
| 4750 | return 1; |
| 4751 | memcpy(qinfo->udata, &qinfo->no_entries, 4); |
| 4752 | /* keep STRIP_ENTRIES flag so the user program can distinguish |
| 4753 | * stripped entries from normal ones */ |
| 4754 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 4755 | qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES; |
| 4756 | memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET,&qdata->reply_bits,2); |
| 4757 | return 0; |
| 4758 | out_error: |
| 4759 | i = 0; |
| 4760 | memcpy(qinfo->udata, &i, 4); |
| 4761 | return 0; |
| 4762 | } |
| 4763 | |
| 4764 | static int |
| 4765 | qeth_send_ipa_arp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 4766 | int len, int (*reply_cb)(struct qeth_card *, |
| 4767 | struct qeth_reply *, |
| 4768 | unsigned long), |
| 4769 | void *reply_param) |
| 4770 | { |
| 4771 | QETH_DBF_TEXT(trace,4,"sendarp"); |
| 4772 | |
| 4773 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 4774 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 4775 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 4776 | return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob, |
| 4777 | reply_cb, reply_param); |
| 4778 | } |
| 4779 | |
| 4780 | static int |
| 4781 | qeth_send_ipa_snmp_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 4782 | int len, int (*reply_cb)(struct qeth_card *, |
| 4783 | struct qeth_reply *, |
| 4784 | unsigned long), |
| 4785 | void *reply_param) |
| 4786 | { |
| 4787 | u16 s1, s2; |
| 4788 | |
| 4789 | QETH_DBF_TEXT(trace,4,"sendsnmp"); |
| 4790 | |
| 4791 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 4792 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 4793 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 4794 | /* adjust PDU length fields in IPA_PDU_HEADER */ |
| 4795 | s1 = (u32) IPA_PDU_HEADER_SIZE + len; |
| 4796 | s2 = (u32) len; |
| 4797 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 4798 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 4799 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 4800 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 4801 | return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob, |
| 4802 | reply_cb, reply_param); |
| 4803 | } |
| 4804 | |
| 4805 | static struct qeth_cmd_buffer * |
| 4806 | qeth_get_setassparms_cmd(struct qeth_card *, enum qeth_ipa_funcs, |
| 4807 | __u16, __u16, enum qeth_prot_versions); |
| 4808 | static int |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 4809 | qeth_arp_query(struct qeth_card *card, char __user *udata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | { |
| 4811 | struct qeth_cmd_buffer *iob; |
| 4812 | struct qeth_arp_query_info qinfo = {0, }; |
| 4813 | int tmp; |
| 4814 | int rc; |
| 4815 | |
| 4816 | QETH_DBF_TEXT(trace,3,"arpquery"); |
| 4817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ |
| 4819 | IPA_ARP_PROCESSING)) { |
| 4820 | PRINT_WARN("ARP processing not supported " |
| 4821 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4822 | return -EOPNOTSUPP; |
| 4823 | } |
| 4824 | /* get size of userspace buffer and mask_bits -> 6 bytes */ |
| 4825 | if (copy_from_user(&qinfo, udata, 6)) |
| 4826 | return -EFAULT; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 4827 | if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; |
| 4830 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 4831 | IPA_CMD_ASS_ARP_QUERY_INFO, |
| 4832 | sizeof(int),QETH_PROT_IPV4); |
| 4833 | |
| 4834 | rc = qeth_send_ipa_arp_cmd(card, iob, |
| 4835 | QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN, |
| 4836 | qeth_arp_query_cb, (void *)&qinfo); |
| 4837 | if (rc) { |
| 4838 | tmp = rc; |
| 4839 | PRINT_WARN("Error while querying ARP cache on %s: %s " |
| 4840 | "(0x%x/%d)\n", |
| 4841 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 4842 | tmp, tmp); |
| 4843 | copy_to_user(udata, qinfo.udata, 4); |
| 4844 | } else { |
| 4845 | copy_to_user(udata, qinfo.udata, qinfo.udata_len); |
| 4846 | } |
| 4847 | kfree(qinfo.udata); |
| 4848 | return rc; |
| 4849 | } |
| 4850 | |
| 4851 | /** |
| 4852 | * SNMP command callback |
| 4853 | */ |
| 4854 | static int |
| 4855 | qeth_snmp_command_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 4856 | unsigned long sdata) |
| 4857 | { |
| 4858 | struct qeth_ipa_cmd *cmd; |
| 4859 | struct qeth_arp_query_info *qinfo; |
| 4860 | struct qeth_snmp_cmd *snmp; |
| 4861 | unsigned char *data; |
| 4862 | __u16 data_len; |
| 4863 | |
| 4864 | QETH_DBF_TEXT(trace,3,"snpcmdcb"); |
| 4865 | |
| 4866 | cmd = (struct qeth_ipa_cmd *) sdata; |
| 4867 | data = (unsigned char *)((char *)cmd - reply->offset); |
| 4868 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 4869 | snmp = &cmd->data.setadapterparms.data.snmp; |
| 4870 | |
| 4871 | if (cmd->hdr.return_code) { |
| 4872 | QETH_DBF_TEXT_(trace,4,"scer1%i", cmd->hdr.return_code); |
| 4873 | return 0; |
| 4874 | } |
| 4875 | if (cmd->data.setadapterparms.hdr.return_code) { |
| 4876 | cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code; |
| 4877 | QETH_DBF_TEXT_(trace,4,"scer2%i", cmd->hdr.return_code); |
| 4878 | return 0; |
| 4879 | } |
| 4880 | data_len = *((__u16*)QETH_IPA_PDU_LEN_PDU1(data)); |
| 4881 | if (cmd->data.setadapterparms.hdr.seq_no == 1) |
| 4882 | data_len -= (__u16)((char *)&snmp->data - (char *)cmd); |
| 4883 | else |
| 4884 | data_len -= (__u16)((char*)&snmp->request - (char *)cmd); |
| 4885 | |
| 4886 | /* check if there is enough room in userspace */ |
| 4887 | if ((qinfo->udata_len - qinfo->udata_offset) < data_len) { |
| 4888 | QETH_DBF_TEXT_(trace, 4, "scer3%i", -ENOMEM); |
| 4889 | cmd->hdr.return_code = -ENOMEM; |
| 4890 | return 0; |
| 4891 | } |
| 4892 | QETH_DBF_TEXT_(trace, 4, "snore%i", |
| 4893 | cmd->data.setadapterparms.hdr.used_total); |
| 4894 | QETH_DBF_TEXT_(trace, 4, "sseqn%i", cmd->data.setadapterparms.hdr.seq_no); |
| 4895 | /*copy entries to user buffer*/ |
| 4896 | if (cmd->data.setadapterparms.hdr.seq_no == 1) { |
| 4897 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4898 | (char *)snmp, |
| 4899 | data_len + offsetof(struct qeth_snmp_cmd,data)); |
| 4900 | qinfo->udata_offset += offsetof(struct qeth_snmp_cmd, data); |
| 4901 | } else { |
| 4902 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 4903 | (char *)&snmp->request, data_len); |
| 4904 | } |
| 4905 | qinfo->udata_offset += data_len; |
| 4906 | /* check if all replies received ... */ |
| 4907 | QETH_DBF_TEXT_(trace, 4, "srtot%i", |
| 4908 | cmd->data.setadapterparms.hdr.used_total); |
| 4909 | QETH_DBF_TEXT_(trace, 4, "srseq%i", |
| 4910 | cmd->data.setadapterparms.hdr.seq_no); |
| 4911 | if (cmd->data.setadapterparms.hdr.seq_no < |
| 4912 | cmd->data.setadapterparms.hdr.used_total) |
| 4913 | return 1; |
| 4914 | return 0; |
| 4915 | } |
| 4916 | |
| 4917 | static struct qeth_cmd_buffer * |
| 4918 | qeth_get_ipacmd_buffer(struct qeth_card *, enum qeth_ipa_cmds, |
| 4919 | enum qeth_prot_versions ); |
| 4920 | |
| 4921 | static struct qeth_cmd_buffer * |
| 4922 | qeth_get_adapter_cmd(struct qeth_card *card, __u32 command, __u32 cmdlen) |
| 4923 | { |
| 4924 | struct qeth_cmd_buffer *iob; |
| 4925 | struct qeth_ipa_cmd *cmd; |
| 4926 | |
| 4927 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETADAPTERPARMS, |
| 4928 | QETH_PROT_IPV4); |
| 4929 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 4930 | cmd->data.setadapterparms.hdr.cmdlength = cmdlen; |
| 4931 | cmd->data.setadapterparms.hdr.command_code = command; |
| 4932 | cmd->data.setadapterparms.hdr.used_total = 1; |
| 4933 | cmd->data.setadapterparms.hdr.seq_no = 1; |
| 4934 | |
| 4935 | return iob; |
| 4936 | } |
| 4937 | |
| 4938 | /** |
| 4939 | * function to send SNMP commands to OSA-E card |
| 4940 | */ |
| 4941 | static int |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 4942 | qeth_snmp_command(struct qeth_card *card, char __user *udata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | { |
| 4944 | struct qeth_cmd_buffer *iob; |
| 4945 | struct qeth_ipa_cmd *cmd; |
| 4946 | struct qeth_snmp_ureq *ureq; |
| 4947 | int req_len; |
| 4948 | struct qeth_arp_query_info qinfo = {0, }; |
| 4949 | int rc = 0; |
| 4950 | |
| 4951 | QETH_DBF_TEXT(trace,3,"snmpcmd"); |
| 4952 | |
| 4953 | if (card->info.guestlan) |
| 4954 | return -EOPNOTSUPP; |
| 4955 | |
| 4956 | if ((!qeth_adp_supported(card,IPA_SETADP_SET_SNMP_CONTROL)) && |
| 4957 | (!card->options.layer2) ) { |
| 4958 | PRINT_WARN("SNMP Query MIBS not supported " |
| 4959 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 4960 | return -EOPNOTSUPP; |
| 4961 | } |
| 4962 | /* skip 4 bytes (data_len struct member) to get req_len */ |
| 4963 | if (copy_from_user(&req_len, udata + sizeof(int), sizeof(int))) |
| 4964 | return -EFAULT; |
| 4965 | ureq = kmalloc(req_len+sizeof(struct qeth_snmp_ureq_hdr), GFP_KERNEL); |
| 4966 | if (!ureq) { |
| 4967 | QETH_DBF_TEXT(trace, 2, "snmpnome"); |
| 4968 | return -ENOMEM; |
| 4969 | } |
| 4970 | if (copy_from_user(ureq, udata, |
| 4971 | req_len+sizeof(struct qeth_snmp_ureq_hdr))){ |
| 4972 | kfree(ureq); |
| 4973 | return -EFAULT; |
| 4974 | } |
| 4975 | qinfo.udata_len = ureq->hdr.data_len; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 4976 | if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | kfree(ureq); |
| 4978 | return -ENOMEM; |
| 4979 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr); |
| 4981 | |
| 4982 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, |
| 4983 | QETH_SNMP_SETADP_CMDLENGTH + req_len); |
| 4984 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 4985 | memcpy(&cmd->data.setadapterparms.data.snmp, &ureq->cmd, req_len); |
| 4986 | rc = qeth_send_ipa_snmp_cmd(card, iob, QETH_SETADP_BASE_LEN + req_len, |
| 4987 | qeth_snmp_command_cb, (void *)&qinfo); |
| 4988 | if (rc) |
| 4989 | PRINT_WARN("SNMP command failed on %s: (0x%x)\n", |
| 4990 | QETH_CARD_IFNAME(card), rc); |
| 4991 | else |
| 4992 | copy_to_user(udata, qinfo.udata, qinfo.udata_len); |
| 4993 | |
| 4994 | kfree(ureq); |
| 4995 | kfree(qinfo.udata); |
| 4996 | return rc; |
| 4997 | } |
| 4998 | |
| 4999 | static int |
| 5000 | qeth_default_setassparms_cb(struct qeth_card *, struct qeth_reply *, |
| 5001 | unsigned long); |
| 5002 | |
| 5003 | static int |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5004 | qeth_default_setadapterparms_cb(struct qeth_card *card, |
| 5005 | struct qeth_reply *reply, |
| 5006 | unsigned long data); |
| 5007 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *, |
| 5009 | __u16, long, |
| 5010 | int (*reply_cb) |
| 5011 | (struct qeth_card *, struct qeth_reply *, unsigned long), |
| 5012 | void *reply_param); |
| 5013 | |
| 5014 | static int |
| 5015 | qeth_arp_add_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry) |
| 5016 | { |
| 5017 | struct qeth_cmd_buffer *iob; |
| 5018 | char buf[16]; |
| 5019 | int tmp; |
| 5020 | int rc; |
| 5021 | |
| 5022 | QETH_DBF_TEXT(trace,3,"arpadent"); |
| 5023 | |
| 5024 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5025 | * currently GuestLAN only supports the ARP assist function |
| 5026 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY; |
| 5027 | * thus we say EOPNOTSUPP for this ARP function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | */ |
| 5029 | if (card->info.guestlan) |
| 5030 | return -EOPNOTSUPP; |
| 5031 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5032 | PRINT_WARN("ARP processing not supported " |
| 5033 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5034 | return -EOPNOTSUPP; |
| 5035 | } |
| 5036 | |
| 5037 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 5038 | IPA_CMD_ASS_ARP_ADD_ENTRY, |
| 5039 | sizeof(struct qeth_arp_cache_entry), |
| 5040 | QETH_PROT_IPV4); |
| 5041 | rc = qeth_send_setassparms(card, iob, |
| 5042 | sizeof(struct qeth_arp_cache_entry), |
| 5043 | (unsigned long) entry, |
| 5044 | qeth_default_setassparms_cb, NULL); |
| 5045 | if (rc) { |
| 5046 | tmp = rc; |
| 5047 | qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
| 5048 | PRINT_WARN("Could not add ARP entry for address %s on %s: " |
| 5049 | "%s (0x%x/%d)\n", |
| 5050 | buf, QETH_CARD_IFNAME(card), |
| 5051 | qeth_arp_get_error_cause(&rc), tmp, tmp); |
| 5052 | } |
| 5053 | return rc; |
| 5054 | } |
| 5055 | |
| 5056 | static int |
| 5057 | qeth_arp_remove_entry(struct qeth_card *card, struct qeth_arp_cache_entry *entry) |
| 5058 | { |
| 5059 | struct qeth_cmd_buffer *iob; |
| 5060 | char buf[16] = {0, }; |
| 5061 | int tmp; |
| 5062 | int rc; |
| 5063 | |
| 5064 | QETH_DBF_TEXT(trace,3,"arprment"); |
| 5065 | |
| 5066 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5067 | * currently GuestLAN only supports the ARP assist function |
| 5068 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY; |
| 5069 | * thus we say EOPNOTSUPP for this ARP function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | */ |
| 5071 | if (card->info.guestlan) |
| 5072 | return -EOPNOTSUPP; |
| 5073 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5074 | PRINT_WARN("ARP processing not supported " |
| 5075 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5076 | return -EOPNOTSUPP; |
| 5077 | } |
| 5078 | memcpy(buf, entry, 12); |
| 5079 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 5080 | IPA_CMD_ASS_ARP_REMOVE_ENTRY, |
| 5081 | 12, |
| 5082 | QETH_PROT_IPV4); |
| 5083 | rc = qeth_send_setassparms(card, iob, |
| 5084 | 12, (unsigned long)buf, |
| 5085 | qeth_default_setassparms_cb, NULL); |
| 5086 | if (rc) { |
| 5087 | tmp = rc; |
| 5088 | memset(buf, 0, 16); |
| 5089 | qeth_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
| 5090 | PRINT_WARN("Could not delete ARP entry for address %s on %s: " |
| 5091 | "%s (0x%x/%d)\n", |
| 5092 | buf, QETH_CARD_IFNAME(card), |
| 5093 | qeth_arp_get_error_cause(&rc), tmp, tmp); |
| 5094 | } |
| 5095 | return rc; |
| 5096 | } |
| 5097 | |
| 5098 | static int |
| 5099 | qeth_arp_flush_cache(struct qeth_card *card) |
| 5100 | { |
| 5101 | int rc; |
| 5102 | int tmp; |
| 5103 | |
| 5104 | QETH_DBF_TEXT(trace,3,"arpflush"); |
| 5105 | |
| 5106 | /* |
Frank Pavlic | f3d242e | 2005-09-14 18:05:31 +0200 | [diff] [blame] | 5107 | * currently GuestLAN only supports the ARP assist function |
| 5108 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE; |
| 5109 | * thus we say EOPNOTSUPP for this ARP function |
| 5110 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD)) |
| 5112 | return -EOPNOTSUPP; |
| 5113 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 5114 | PRINT_WARN("ARP processing not supported " |
| 5115 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 5116 | return -EOPNOTSUPP; |
| 5117 | } |
| 5118 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 5119 | IPA_CMD_ASS_ARP_FLUSH_CACHE, 0); |
| 5120 | if (rc){ |
| 5121 | tmp = rc; |
| 5122 | PRINT_WARN("Could not flush ARP cache on %s: %s (0x%x/%d)\n", |
| 5123 | QETH_CARD_IFNAME(card), qeth_arp_get_error_cause(&rc), |
| 5124 | tmp, tmp); |
| 5125 | } |
| 5126 | return rc; |
| 5127 | } |
| 5128 | |
| 5129 | static int |
| 5130 | qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 5131 | { |
| 5132 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 5133 | struct qeth_arp_cache_entry arp_entry; |
| 5134 | struct mii_ioctl_data *mii_data; |
| 5135 | int rc = 0; |
| 5136 | |
| 5137 | if (!card) |
| 5138 | return -ENODEV; |
| 5139 | |
| 5140 | if ((card->state != CARD_STATE_UP) && |
| 5141 | (card->state != CARD_STATE_SOFTSETUP)) |
| 5142 | return -ENODEV; |
| 5143 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5144 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 5145 | return -EPERM; |
| 5146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | switch (cmd){ |
| 5148 | case SIOC_QETH_ARP_SET_NO_ENTRIES: |
| 5149 | if ( !capable(CAP_NET_ADMIN) || |
| 5150 | (card->options.layer2) ) { |
| 5151 | rc = -EPERM; |
| 5152 | break; |
| 5153 | } |
| 5154 | rc = qeth_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue); |
| 5155 | break; |
| 5156 | case SIOC_QETH_ARP_QUERY_INFO: |
| 5157 | if ( !capable(CAP_NET_ADMIN) || |
| 5158 | (card->options.layer2) ) { |
| 5159 | rc = -EPERM; |
| 5160 | break; |
| 5161 | } |
| 5162 | rc = qeth_arp_query(card, rq->ifr_ifru.ifru_data); |
| 5163 | break; |
| 5164 | case SIOC_QETH_ARP_ADD_ENTRY: |
| 5165 | if ( !capable(CAP_NET_ADMIN) || |
| 5166 | (card->options.layer2) ) { |
| 5167 | rc = -EPERM; |
| 5168 | break; |
| 5169 | } |
| 5170 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 5171 | sizeof(struct qeth_arp_cache_entry))) |
| 5172 | rc = -EFAULT; |
| 5173 | else |
| 5174 | rc = qeth_arp_add_entry(card, &arp_entry); |
| 5175 | break; |
| 5176 | case SIOC_QETH_ARP_REMOVE_ENTRY: |
| 5177 | if ( !capable(CAP_NET_ADMIN) || |
| 5178 | (card->options.layer2) ) { |
| 5179 | rc = -EPERM; |
| 5180 | break; |
| 5181 | } |
| 5182 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 5183 | sizeof(struct qeth_arp_cache_entry))) |
| 5184 | rc = -EFAULT; |
| 5185 | else |
| 5186 | rc = qeth_arp_remove_entry(card, &arp_entry); |
| 5187 | break; |
| 5188 | case SIOC_QETH_ARP_FLUSH_CACHE: |
| 5189 | if ( !capable(CAP_NET_ADMIN) || |
| 5190 | (card->options.layer2) ) { |
| 5191 | rc = -EPERM; |
| 5192 | break; |
| 5193 | } |
| 5194 | rc = qeth_arp_flush_cache(card); |
| 5195 | break; |
| 5196 | case SIOC_QETH_ADP_SET_SNMP_CONTROL: |
| 5197 | rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data); |
| 5198 | break; |
| 5199 | case SIOC_QETH_GET_CARD_TYPE: |
| 5200 | if ((card->info.type == QETH_CARD_TYPE_OSAE) && |
| 5201 | !card->info.guestlan) |
| 5202 | return 1; |
| 5203 | return 0; |
| 5204 | break; |
| 5205 | case SIOCGMIIPHY: |
| 5206 | mii_data = if_mii(rq); |
| 5207 | mii_data->phy_id = 0; |
| 5208 | break; |
| 5209 | case SIOCGMIIREG: |
| 5210 | mii_data = if_mii(rq); |
| 5211 | if (mii_data->phy_id != 0) |
| 5212 | rc = -EINVAL; |
| 5213 | else |
| 5214 | mii_data->val_out = qeth_mdio_read(dev,mii_data->phy_id, |
| 5215 | mii_data->reg_num); |
| 5216 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | default: |
| 5218 | rc = -EOPNOTSUPP; |
| 5219 | } |
| 5220 | if (rc) |
| 5221 | QETH_DBF_TEXT_(trace, 2, "ioce%d", rc); |
| 5222 | return rc; |
| 5223 | } |
| 5224 | |
| 5225 | static struct net_device_stats * |
| 5226 | qeth_get_stats(struct net_device *dev) |
| 5227 | { |
| 5228 | struct qeth_card *card; |
| 5229 | |
| 5230 | card = (struct qeth_card *) (dev->priv); |
| 5231 | |
| 5232 | QETH_DBF_TEXT(trace,5,"getstat"); |
| 5233 | |
| 5234 | return &card->stats; |
| 5235 | } |
| 5236 | |
| 5237 | static int |
| 5238 | qeth_change_mtu(struct net_device *dev, int new_mtu) |
| 5239 | { |
| 5240 | struct qeth_card *card; |
| 5241 | char dbf_text[15]; |
| 5242 | |
| 5243 | card = (struct qeth_card *) (dev->priv); |
| 5244 | |
| 5245 | QETH_DBF_TEXT(trace,4,"chgmtu"); |
| 5246 | sprintf(dbf_text, "%8x", new_mtu); |
| 5247 | QETH_DBF_TEXT(trace,4,dbf_text); |
| 5248 | |
| 5249 | if (new_mtu < 64) |
| 5250 | return -EINVAL; |
| 5251 | if (new_mtu > 65535) |
| 5252 | return -EINVAL; |
| 5253 | if ((!qeth_is_supported(card,IPA_IP_FRAGMENTATION)) && |
| 5254 | (!qeth_mtu_is_valid(card, new_mtu))) |
| 5255 | return -EINVAL; |
| 5256 | dev->mtu = new_mtu; |
| 5257 | return 0; |
| 5258 | } |
| 5259 | |
| 5260 | #ifdef CONFIG_QETH_VLAN |
| 5261 | static void |
| 5262 | qeth_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 5263 | { |
| 5264 | struct qeth_card *card; |
| 5265 | unsigned long flags; |
| 5266 | |
| 5267 | QETH_DBF_TEXT(trace,4,"vlanreg"); |
| 5268 | |
| 5269 | card = (struct qeth_card *) dev->priv; |
| 5270 | spin_lock_irqsave(&card->vlanlock, flags); |
| 5271 | card->vlangrp = grp; |
| 5272 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 5273 | } |
| 5274 | |
| 5275 | static inline void |
| 5276 | qeth_free_vlan_buffer(struct qeth_card *card, struct qeth_qdio_out_buffer *buf, |
| 5277 | unsigned short vid) |
| 5278 | { |
| 5279 | int i; |
| 5280 | struct sk_buff *skb; |
| 5281 | struct sk_buff_head tmp_list; |
| 5282 | |
| 5283 | skb_queue_head_init(&tmp_list); |
Heiko Carstens | 91ebe2a | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 5284 | lockdep_set_class(&tmp_list.lock, &qdio_out_skb_queue_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | for(i = 0; i < QETH_MAX_BUFFER_ELEMENTS(card); ++i){ |
| 5286 | while ((skb = skb_dequeue(&buf->skb_list))){ |
| 5287 | if (vlan_tx_tag_present(skb) && |
| 5288 | (vlan_tx_tag_get(skb) == vid)) { |
| 5289 | atomic_dec(&skb->users); |
| 5290 | dev_kfree_skb(skb); |
| 5291 | } else |
| 5292 | skb_queue_tail(&tmp_list, skb); |
| 5293 | } |
| 5294 | } |
| 5295 | while ((skb = skb_dequeue(&tmp_list))) |
| 5296 | skb_queue_tail(&buf->skb_list, skb); |
| 5297 | } |
| 5298 | |
| 5299 | static void |
| 5300 | qeth_free_vlan_skbs(struct qeth_card *card, unsigned short vid) |
| 5301 | { |
| 5302 | int i, j; |
| 5303 | |
| 5304 | QETH_DBF_TEXT(trace, 4, "frvlskbs"); |
| 5305 | for (i = 0; i < card->qdio.no_out_queues; ++i){ |
| 5306 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; ++j) |
| 5307 | qeth_free_vlan_buffer(card, &card->qdio. |
| 5308 | out_qs[i]->bufs[j], vid); |
| 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | static void |
| 5313 | qeth_free_vlan_addresses4(struct qeth_card *card, unsigned short vid) |
| 5314 | { |
| 5315 | struct in_device *in_dev; |
| 5316 | struct in_ifaddr *ifa; |
| 5317 | struct qeth_ipaddr *addr; |
| 5318 | |
| 5319 | QETH_DBF_TEXT(trace, 4, "frvaddr4"); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 5322 | in_dev = __in_dev_get_rcu(card->vlangrp->vlan_devices[vid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 | if (!in_dev) |
| 5324 | goto out; |
| 5325 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 5326 | addr = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5327 | if (addr){ |
| 5328 | addr->u.a4.addr = ifa->ifa_address; |
| 5329 | addr->u.a4.mask = ifa->ifa_mask; |
| 5330 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5331 | if (!qeth_delete_ip(card, addr)) |
| 5332 | kfree(addr); |
| 5333 | } |
| 5334 | } |
| 5335 | out: |
| 5336 | rcu_read_unlock(); |
| 5337 | } |
| 5338 | |
| 5339 | static void |
| 5340 | qeth_free_vlan_addresses6(struct qeth_card *card, unsigned short vid) |
| 5341 | { |
| 5342 | #ifdef CONFIG_QETH_IPV6 |
| 5343 | struct inet6_dev *in6_dev; |
| 5344 | struct inet6_ifaddr *ifa; |
| 5345 | struct qeth_ipaddr *addr; |
| 5346 | |
| 5347 | QETH_DBF_TEXT(trace, 4, "frvaddr6"); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | in6_dev = in6_dev_get(card->vlangrp->vlan_devices[vid]); |
| 5350 | if (!in6_dev) |
| 5351 | return; |
| 5352 | for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next){ |
| 5353 | addr = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 5354 | if (addr){ |
| 5355 | memcpy(&addr->u.a6.addr, &ifa->addr, |
| 5356 | sizeof(struct in6_addr)); |
| 5357 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 5358 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5359 | if (!qeth_delete_ip(card, addr)) |
| 5360 | kfree(addr); |
| 5361 | } |
| 5362 | } |
| 5363 | in6_dev_put(in6_dev); |
| 5364 | #endif /* CONFIG_QETH_IPV6 */ |
| 5365 | } |
| 5366 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5367 | static void |
| 5368 | qeth_free_vlan_addresses(struct qeth_card *card, unsigned short vid) |
| 5369 | { |
| 5370 | if (card->options.layer2 || !card->vlangrp) |
| 5371 | return; |
| 5372 | qeth_free_vlan_addresses4(card, vid); |
| 5373 | qeth_free_vlan_addresses6(card, vid); |
| 5374 | } |
| 5375 | |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5376 | static int |
| 5377 | qeth_layer2_send_setdelvlan_cb(struct qeth_card *card, |
| 5378 | struct qeth_reply *reply, |
| 5379 | unsigned long data) |
| 5380 | { |
| 5381 | struct qeth_ipa_cmd *cmd; |
| 5382 | |
| 5383 | QETH_DBF_TEXT(trace, 2, "L2sdvcb"); |
| 5384 | cmd = (struct qeth_ipa_cmd *) data; |
| 5385 | if (cmd->hdr.return_code) { |
| 5386 | PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. " |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5387 | "Continuing\n",cmd->data.setdelvlan.vlan_id, |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5388 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
| 5389 | QETH_DBF_TEXT_(trace, 2, "L2VL%4x", cmd->hdr.command); |
| 5390 | QETH_DBF_TEXT_(trace, 2, "L2%s", CARD_BUS_ID(card)); |
| 5391 | QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code); |
| 5392 | } |
| 5393 | return 0; |
| 5394 | } |
| 5395 | |
| 5396 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | qeth_layer2_send_setdelvlan(struct qeth_card *card, __u16 i, |
| 5398 | enum qeth_ipa_cmds ipacmd) |
| 5399 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | struct qeth_ipa_cmd *cmd; |
| 5401 | struct qeth_cmd_buffer *iob; |
| 5402 | |
| 5403 | QETH_DBF_TEXT_(trace, 4, "L2sdv%x",ipacmd); |
| 5404 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 5405 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 5406 | cmd->data.setdelvlan.vlan_id = i; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5407 | return qeth_send_ipa_cmd(card, iob, |
Frank Pavlic | 508cc2b | 2005-11-10 13:49:15 +0100 | [diff] [blame] | 5408 | qeth_layer2_send_setdelvlan_cb, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | static void |
| 5412 | qeth_layer2_process_vlans(struct qeth_card *card, int clear) |
| 5413 | { |
| 5414 | unsigned short i; |
| 5415 | |
| 5416 | QETH_DBF_TEXT(trace, 3, "L2prcvln"); |
| 5417 | |
| 5418 | if (!card->vlangrp) |
| 5419 | return; |
| 5420 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5421 | if (card->vlangrp->vlan_devices[i] == NULL) |
| 5422 | continue; |
| 5423 | if (clear) |
| 5424 | qeth_layer2_send_setdelvlan(card, i, IPA_CMD_DELVLAN); |
| 5425 | else |
| 5426 | qeth_layer2_send_setdelvlan(card, i, IPA_CMD_SETVLAN); |
| 5427 | } |
| 5428 | } |
| 5429 | |
| 5430 | /*add_vid is layer 2 used only ....*/ |
| 5431 | static void |
| 5432 | qeth_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 5433 | { |
| 5434 | struct qeth_card *card; |
| 5435 | |
| 5436 | QETH_DBF_TEXT_(trace, 4, "aid:%d", vid); |
| 5437 | |
| 5438 | card = (struct qeth_card *) dev->priv; |
| 5439 | if (!card->options.layer2) |
| 5440 | return; |
| 5441 | qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
| 5442 | } |
| 5443 | |
| 5444 | /*... kill_vid used for both modes*/ |
| 5445 | static void |
| 5446 | qeth_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 5447 | { |
| 5448 | struct qeth_card *card; |
| 5449 | unsigned long flags; |
| 5450 | |
| 5451 | QETH_DBF_TEXT_(trace, 4, "kid:%d", vid); |
| 5452 | |
| 5453 | card = (struct qeth_card *) dev->priv; |
| 5454 | /* free all skbs for the vlan device */ |
| 5455 | qeth_free_vlan_skbs(card, vid); |
| 5456 | spin_lock_irqsave(&card->vlanlock, flags); |
| 5457 | /* unregister IP addresses of vlan device */ |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5458 | qeth_free_vlan_addresses(card, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5459 | if (card->vlangrp) |
| 5460 | card->vlangrp->vlan_devices[vid] = NULL; |
| 5461 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 5462 | if (card->options.layer2) |
| 5463 | qeth_layer2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
| 5464 | qeth_set_multicast_list(card->dev); |
| 5465 | } |
| 5466 | #endif |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5467 | /** |
| 5468 | * Examine hardware response to SET_PROMISC_MODE |
| 5469 | */ |
| 5470 | static int |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5471 | qeth_setadp_promisc_mode_cb(struct qeth_card *card, |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5472 | struct qeth_reply *reply, |
| 5473 | unsigned long data) |
| 5474 | { |
| 5475 | struct qeth_ipa_cmd *cmd; |
| 5476 | struct qeth_ipacmd_setadpparms *setparms; |
| 5477 | |
| 5478 | QETH_DBF_TEXT(trace,4,"prmadpcb"); |
| 5479 | |
| 5480 | cmd = (struct qeth_ipa_cmd *) data; |
| 5481 | setparms = &(cmd->data.setadapterparms); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5482 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5483 | qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5484 | if (cmd->hdr.return_code) { |
| 5485 | QETH_DBF_TEXT_(trace,4,"prmrc%2.2x",cmd->hdr.return_code); |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5486 | setparms->data.mode = SET_PROMISC_MODE_OFF; |
| 5487 | } |
| 5488 | card->info.promisc_mode = setparms->data.mode; |
| 5489 | return 0; |
| 5490 | } |
| 5491 | /* |
| 5492 | * Set promiscuous mode (on or off) (SET_PROMISC_MODE command) |
| 5493 | */ |
| 5494 | static void |
| 5495 | qeth_setadp_promisc_mode(struct qeth_card *card) |
| 5496 | { |
| 5497 | enum qeth_ipa_promisc_modes mode; |
| 5498 | struct net_device *dev = card->dev; |
| 5499 | struct qeth_cmd_buffer *iob; |
| 5500 | struct qeth_ipa_cmd *cmd; |
| 5501 | |
| 5502 | QETH_DBF_TEXT(trace, 4, "setprom"); |
| 5503 | |
| 5504 | if (((dev->flags & IFF_PROMISC) && |
| 5505 | (card->info.promisc_mode == SET_PROMISC_MODE_ON)) || |
| 5506 | (!(dev->flags & IFF_PROMISC) && |
| 5507 | (card->info.promisc_mode == SET_PROMISC_MODE_OFF))) |
| 5508 | return; |
| 5509 | mode = SET_PROMISC_MODE_OFF; |
| 5510 | if (dev->flags & IFF_PROMISC) |
| 5511 | mode = SET_PROMISC_MODE_ON; |
| 5512 | QETH_DBF_TEXT_(trace, 4, "mode:%x", mode); |
| 5513 | |
| 5514 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_PROMISC_MODE, |
| 5515 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 5516 | cmd = (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE); |
| 5517 | cmd->data.setadapterparms.data.mode = mode; |
| 5518 | qeth_send_ipa_cmd(card, iob, qeth_setadp_promisc_mode_cb, NULL); |
| 5519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | |
| 5521 | /** |
| 5522 | * set multicast address on card |
| 5523 | */ |
| 5524 | static void |
| 5525 | qeth_set_multicast_list(struct net_device *dev) |
| 5526 | { |
| 5527 | struct qeth_card *card = (struct qeth_card *) dev->priv; |
| 5528 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5529 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 5530 | return ; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5531 | |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 5532 | QETH_DBF_TEXT(trace, 3, "setmulti"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | qeth_delete_mc_addresses(card); |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5534 | if (card->options.layer2) { |
| 5535 | qeth_layer2_add_multicast(card); |
| 5536 | goto out; |
| 5537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | qeth_add_multicast_ipv4(card); |
| 5539 | #ifdef CONFIG_QETH_IPV6 |
| 5540 | qeth_add_multicast_ipv6(card); |
| 5541 | #endif |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5542 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 5544 | schedule_work(&card->kernel_thread_starter); |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 5545 | if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 5546 | return; |
| 5547 | if (qeth_set_thread_start_bit(card, QETH_SET_PROMISC_MODE_THREAD)==0) |
| 5548 | schedule_work(&card->kernel_thread_starter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | static int |
| 5552 | qeth_neigh_setup(struct net_device *dev, struct neigh_parms *np) |
| 5553 | { |
| 5554 | return 0; |
| 5555 | } |
| 5556 | |
| 5557 | static void |
| 5558 | qeth_get_mac_for_ipm(__u32 ipm, char *mac, struct net_device *dev) |
| 5559 | { |
| 5560 | if (dev->type == ARPHRD_IEEE802_TR) |
| 5561 | ip_tr_mc_map(ipm, mac); |
| 5562 | else |
| 5563 | ip_eth_mc_map(ipm, mac); |
| 5564 | } |
| 5565 | |
| 5566 | static struct qeth_ipaddr * |
| 5567 | qeth_get_addr_buffer(enum qeth_prot_versions prot) |
| 5568 | { |
| 5569 | struct qeth_ipaddr *addr; |
| 5570 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 5571 | addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | if (addr == NULL) { |
| 5573 | PRINT_WARN("Not enough memory to add address\n"); |
| 5574 | return NULL; |
| 5575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | addr->type = QETH_IP_TYPE_NORMAL; |
| 5577 | addr->proto = prot; |
| 5578 | return addr; |
| 5579 | } |
| 5580 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5581 | int |
| 5582 | qeth_osn_assist(struct net_device *dev, |
| 5583 | void *data, |
| 5584 | int data_len) |
| 5585 | { |
| 5586 | struct qeth_cmd_buffer *iob; |
| 5587 | struct qeth_card *card; |
| 5588 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5589 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 5590 | QETH_DBF_TEXT(trace, 2, "osnsdmc"); |
| 5591 | if (!dev) |
| 5592 | return -ENODEV; |
| 5593 | card = (struct qeth_card *)dev->priv; |
| 5594 | if (!card) |
| 5595 | return -ENODEV; |
| 5596 | if ((card->state != CARD_STATE_UP) && |
| 5597 | (card->state != CARD_STATE_SOFTSETUP)) |
| 5598 | return -ENODEV; |
| 5599 | iob = qeth_wait_for_buffer(&card->write); |
| 5600 | memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); |
| 5601 | rc = qeth_osn_send_ipa_cmd(card, iob, data_len); |
| 5602 | return rc; |
| 5603 | } |
| 5604 | |
| 5605 | static struct net_device * |
| 5606 | qeth_netdev_by_devno(unsigned char *read_dev_no) |
| 5607 | { |
| 5608 | struct qeth_card *card; |
| 5609 | struct net_device *ndev; |
| 5610 | unsigned char *readno; |
| 5611 | __u16 temp_dev_no, card_dev_no; |
| 5612 | char *endp; |
| 5613 | unsigned long flags; |
| 5614 | |
| 5615 | ndev = NULL; |
| 5616 | memcpy(&temp_dev_no, read_dev_no, 2); |
| 5617 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 5618 | list_for_each_entry(card, &qeth_card_list.list, list) { |
| 5619 | readno = CARD_RDEV_ID(card); |
| 5620 | readno += (strlen(readno) - 4); |
| 5621 | card_dev_no = simple_strtoul(readno, &endp, 16); |
| 5622 | if (card_dev_no == temp_dev_no) { |
| 5623 | ndev = card->dev; |
| 5624 | break; |
| 5625 | } |
| 5626 | } |
| 5627 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 5628 | return ndev; |
| 5629 | } |
| 5630 | |
| 5631 | int |
| 5632 | qeth_osn_register(unsigned char *read_dev_no, |
| 5633 | struct net_device **dev, |
| 5634 | int (*assist_cb)(struct net_device *, void *), |
| 5635 | int (*data_cb)(struct sk_buff *)) |
| 5636 | { |
| 5637 | struct qeth_card * card; |
| 5638 | |
| 5639 | QETH_DBF_TEXT(trace, 2, "osnreg"); |
| 5640 | *dev = qeth_netdev_by_devno(read_dev_no); |
| 5641 | if (*dev == NULL) |
| 5642 | return -ENODEV; |
| 5643 | card = (struct qeth_card *)(*dev)->priv; |
| 5644 | if (!card) |
| 5645 | return -ENODEV; |
| 5646 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 5647 | return -EINVAL; |
| 5648 | card->osn_info.assist_cb = assist_cb; |
| 5649 | card->osn_info.data_cb = data_cb; |
| 5650 | return 0; |
| 5651 | } |
| 5652 | |
| 5653 | void |
| 5654 | qeth_osn_deregister(struct net_device * dev) |
| 5655 | { |
| 5656 | struct qeth_card *card; |
| 5657 | |
| 5658 | QETH_DBF_TEXT(trace, 2, "osndereg"); |
| 5659 | if (!dev) |
| 5660 | return; |
| 5661 | card = (struct qeth_card *)dev->priv; |
| 5662 | if (!card) |
| 5663 | return; |
| 5664 | card->osn_info.assist_cb = NULL; |
| 5665 | card->osn_info.data_cb = NULL; |
| 5666 | return; |
| 5667 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | static void |
| 5670 | qeth_delete_mc_addresses(struct qeth_card *card) |
| 5671 | { |
| 5672 | struct qeth_ipaddr *iptodo; |
| 5673 | unsigned long flags; |
| 5674 | |
| 5675 | QETH_DBF_TEXT(trace,4,"delmc"); |
| 5676 | iptodo = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5677 | if (!iptodo) { |
| 5678 | QETH_DBF_TEXT(trace, 2, "dmcnomem"); |
| 5679 | return; |
| 5680 | } |
| 5681 | iptodo->type = QETH_IP_TYPE_DEL_ALL_MC; |
| 5682 | spin_lock_irqsave(&card->ip_lock, flags); |
| 5683 | if (!__qeth_insert_ip_todo(card, iptodo, 0)) |
| 5684 | kfree(iptodo); |
| 5685 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 5686 | } |
| 5687 | |
| 5688 | static inline void |
| 5689 | qeth_add_mc(struct qeth_card *card, struct in_device *in4_dev) |
| 5690 | { |
| 5691 | struct qeth_ipaddr *ipm; |
| 5692 | struct ip_mc_list *im4; |
| 5693 | char buf[MAX_ADDR_LEN]; |
| 5694 | |
| 5695 | QETH_DBF_TEXT(trace,4,"addmc"); |
| 5696 | for (im4 = in4_dev->mc_list; im4; im4 = im4->next) { |
| 5697 | qeth_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev); |
| 5698 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5699 | if (!ipm) |
| 5700 | continue; |
| 5701 | ipm->u.a4.addr = im4->multiaddr; |
| 5702 | memcpy(ipm->mac,buf,OSA_ADDR_LEN); |
| 5703 | ipm->is_multicast = 1; |
| 5704 | if (!qeth_add_ip(card,ipm)) |
| 5705 | kfree(ipm); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | static inline void |
| 5710 | qeth_add_vlan_mc(struct qeth_card *card) |
| 5711 | { |
| 5712 | #ifdef CONFIG_QETH_VLAN |
| 5713 | struct in_device *in_dev; |
| 5714 | struct vlan_group *vg; |
| 5715 | int i; |
| 5716 | |
| 5717 | QETH_DBF_TEXT(trace,4,"addmcvl"); |
| 5718 | if ( ((card->options.layer2 == 0) && |
| 5719 | (!qeth_is_supported(card,IPA_FULL_VLAN))) || |
| 5720 | (card->vlangrp == NULL) ) |
| 5721 | return ; |
| 5722 | |
| 5723 | vg = card->vlangrp; |
| 5724 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5725 | if (vg->vlan_devices[i] == NULL || |
| 5726 | !(vg->vlan_devices[i]->flags & IFF_UP)) |
| 5727 | continue; |
| 5728 | in_dev = in_dev_get(vg->vlan_devices[i]); |
| 5729 | if (!in_dev) |
| 5730 | continue; |
| 5731 | read_lock(&in_dev->mc_list_lock); |
| 5732 | qeth_add_mc(card,in_dev); |
| 5733 | read_unlock(&in_dev->mc_list_lock); |
| 5734 | in_dev_put(in_dev); |
| 5735 | } |
| 5736 | #endif |
| 5737 | } |
| 5738 | |
| 5739 | static void |
| 5740 | qeth_add_multicast_ipv4(struct qeth_card *card) |
| 5741 | { |
| 5742 | struct in_device *in4_dev; |
| 5743 | |
| 5744 | QETH_DBF_TEXT(trace,4,"chkmcv4"); |
| 5745 | in4_dev = in_dev_get(card->dev); |
| 5746 | if (in4_dev == NULL) |
| 5747 | return; |
| 5748 | read_lock(&in4_dev->mc_list_lock); |
| 5749 | qeth_add_mc(card, in4_dev); |
| 5750 | qeth_add_vlan_mc(card); |
| 5751 | read_unlock(&in4_dev->mc_list_lock); |
| 5752 | in_dev_put(in4_dev); |
| 5753 | } |
| 5754 | |
Frank Pavlic | 6c88ad2 | 2005-11-10 13:49:28 +0100 | [diff] [blame] | 5755 | static void |
| 5756 | qeth_layer2_add_multicast(struct qeth_card *card) |
| 5757 | { |
| 5758 | struct qeth_ipaddr *ipm; |
| 5759 | struct dev_mc_list *dm; |
| 5760 | |
| 5761 | QETH_DBF_TEXT(trace,4,"L2addmc"); |
| 5762 | for (dm = card->dev->mc_list; dm; dm = dm->next) { |
| 5763 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 5764 | if (!ipm) |
| 5765 | continue; |
| 5766 | memcpy(ipm->mac,dm->dmi_addr,MAX_ADDR_LEN); |
| 5767 | ipm->is_multicast = 1; |
| 5768 | if (!qeth_add_ip(card, ipm)) |
| 5769 | kfree(ipm); |
| 5770 | } |
| 5771 | } |
| 5772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | #ifdef CONFIG_QETH_IPV6 |
| 5774 | static inline void |
| 5775 | qeth_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev) |
| 5776 | { |
| 5777 | struct qeth_ipaddr *ipm; |
| 5778 | struct ifmcaddr6 *im6; |
| 5779 | char buf[MAX_ADDR_LEN]; |
| 5780 | |
| 5781 | QETH_DBF_TEXT(trace,4,"addmc6"); |
| 5782 | for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { |
| 5783 | ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0); |
| 5784 | ipm = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 5785 | if (!ipm) |
| 5786 | continue; |
| 5787 | ipm->is_multicast = 1; |
| 5788 | memcpy(ipm->mac,buf,OSA_ADDR_LEN); |
| 5789 | memcpy(&ipm->u.a6.addr,&im6->mca_addr.s6_addr, |
| 5790 | sizeof(struct in6_addr)); |
| 5791 | if (!qeth_add_ip(card,ipm)) |
| 5792 | kfree(ipm); |
| 5793 | } |
| 5794 | } |
| 5795 | |
| 5796 | static inline void |
| 5797 | qeth_add_vlan_mc6(struct qeth_card *card) |
| 5798 | { |
| 5799 | #ifdef CONFIG_QETH_VLAN |
| 5800 | struct inet6_dev *in_dev; |
| 5801 | struct vlan_group *vg; |
| 5802 | int i; |
| 5803 | |
| 5804 | QETH_DBF_TEXT(trace,4,"admc6vl"); |
| 5805 | if ( ((card->options.layer2 == 0) && |
| 5806 | (!qeth_is_supported(card,IPA_FULL_VLAN))) || |
| 5807 | (card->vlangrp == NULL)) |
| 5808 | return ; |
| 5809 | |
| 5810 | vg = card->vlangrp; |
| 5811 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 5812 | if (vg->vlan_devices[i] == NULL || |
| 5813 | !(vg->vlan_devices[i]->flags & IFF_UP)) |
| 5814 | continue; |
| 5815 | in_dev = in6_dev_get(vg->vlan_devices[i]); |
| 5816 | if (!in_dev) |
| 5817 | continue; |
| 5818 | read_lock(&in_dev->lock); |
| 5819 | qeth_add_mc6(card,in_dev); |
| 5820 | read_unlock(&in_dev->lock); |
| 5821 | in6_dev_put(in_dev); |
| 5822 | } |
| 5823 | #endif /* CONFIG_QETH_VLAN */ |
| 5824 | } |
| 5825 | |
| 5826 | static void |
| 5827 | qeth_add_multicast_ipv6(struct qeth_card *card) |
| 5828 | { |
| 5829 | struct inet6_dev *in6_dev; |
| 5830 | |
| 5831 | QETH_DBF_TEXT(trace,4,"chkmcv6"); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 5832 | if (!qeth_is_supported(card, IPA_IPV6)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | return ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | in6_dev = in6_dev_get(card->dev); |
| 5835 | if (in6_dev == NULL) |
| 5836 | return; |
| 5837 | read_lock(&in6_dev->lock); |
| 5838 | qeth_add_mc6(card, in6_dev); |
| 5839 | qeth_add_vlan_mc6(card); |
| 5840 | read_unlock(&in6_dev->lock); |
| 5841 | in6_dev_put(in6_dev); |
| 5842 | } |
| 5843 | #endif /* CONFIG_QETH_IPV6 */ |
| 5844 | |
| 5845 | static int |
| 5846 | qeth_layer2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 5847 | enum qeth_ipa_cmds ipacmd, |
| 5848 | int (*reply_cb) (struct qeth_card *, |
| 5849 | struct qeth_reply*, |
| 5850 | unsigned long)) |
| 5851 | { |
| 5852 | struct qeth_ipa_cmd *cmd; |
| 5853 | struct qeth_cmd_buffer *iob; |
| 5854 | |
| 5855 | QETH_DBF_TEXT(trace, 2, "L2sdmac"); |
| 5856 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 5857 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 5858 | cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; |
| 5859 | memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); |
| 5860 | return qeth_send_ipa_cmd(card, iob, reply_cb, NULL); |
| 5861 | } |
| 5862 | |
| 5863 | static int |
| 5864 | qeth_layer2_send_setgroupmac_cb(struct qeth_card *card, |
| 5865 | struct qeth_reply *reply, |
| 5866 | unsigned long data) |
| 5867 | { |
| 5868 | struct qeth_ipa_cmd *cmd; |
| 5869 | __u8 *mac; |
| 5870 | |
| 5871 | QETH_DBF_TEXT(trace, 2, "L2Sgmacb"); |
| 5872 | cmd = (struct qeth_ipa_cmd *) data; |
| 5873 | mac = &cmd->data.setdelmac.mac[0]; |
| 5874 | /* MAC already registered, needed in couple/uncouple case */ |
| 5875 | if (cmd->hdr.return_code == 0x2005) { |
| 5876 | PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \ |
| 5877 | "already existing on %s \n", |
| 5878 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5879 | QETH_CARD_IFNAME(card)); |
| 5880 | cmd->hdr.return_code = 0; |
| 5881 | } |
| 5882 | if (cmd->hdr.return_code) |
| 5883 | PRINT_ERR("Could not set group MAC " \ |
| 5884 | "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n", |
| 5885 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5886 | QETH_CARD_IFNAME(card),cmd->hdr.return_code); |
| 5887 | return 0; |
| 5888 | } |
| 5889 | |
| 5890 | static int |
| 5891 | qeth_layer2_send_setgroupmac(struct qeth_card *card, __u8 *mac) |
| 5892 | { |
| 5893 | QETH_DBF_TEXT(trace, 2, "L2Sgmac"); |
| 5894 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETGMAC, |
| 5895 | qeth_layer2_send_setgroupmac_cb); |
| 5896 | } |
| 5897 | |
| 5898 | static int |
| 5899 | qeth_layer2_send_delgroupmac_cb(struct qeth_card *card, |
| 5900 | struct qeth_reply *reply, |
| 5901 | unsigned long data) |
| 5902 | { |
| 5903 | struct qeth_ipa_cmd *cmd; |
| 5904 | __u8 *mac; |
| 5905 | |
| 5906 | QETH_DBF_TEXT(trace, 2, "L2Dgmacb"); |
| 5907 | cmd = (struct qeth_ipa_cmd *) data; |
| 5908 | mac = &cmd->data.setdelmac.mac[0]; |
| 5909 | if (cmd->hdr.return_code) |
| 5910 | PRINT_ERR("Could not delete group MAC " \ |
| 5911 | "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n", |
| 5912 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], |
| 5913 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
| 5914 | return 0; |
| 5915 | } |
| 5916 | |
| 5917 | static int |
| 5918 | qeth_layer2_send_delgroupmac(struct qeth_card *card, __u8 *mac) |
| 5919 | { |
| 5920 | QETH_DBF_TEXT(trace, 2, "L2Dgmac"); |
| 5921 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELGMAC, |
| 5922 | qeth_layer2_send_delgroupmac_cb); |
| 5923 | } |
| 5924 | |
| 5925 | static int |
| 5926 | qeth_layer2_send_setmac_cb(struct qeth_card *card, |
| 5927 | struct qeth_reply *reply, |
| 5928 | unsigned long data) |
| 5929 | { |
| 5930 | struct qeth_ipa_cmd *cmd; |
| 5931 | |
| 5932 | QETH_DBF_TEXT(trace, 2, "L2Smaccb"); |
| 5933 | cmd = (struct qeth_ipa_cmd *) data; |
| 5934 | if (cmd->hdr.return_code) { |
| 5935 | QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code); |
| 5936 | PRINT_WARN("Error in registering MAC address on " \ |
| 5937 | "device %s: x%x\n", CARD_BUS_ID(card), |
| 5938 | cmd->hdr.return_code); |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5939 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | cmd->hdr.return_code = -EIO; |
| 5941 | } else { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5942 | card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5943 | memcpy(card->dev->dev_addr,cmd->data.setdelmac.mac, |
| 5944 | OSA_ADDR_LEN); |
| 5945 | PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " |
| 5946 | "successfully registered on device %s\n", |
| 5947 | card->dev->dev_addr[0], card->dev->dev_addr[1], |
| 5948 | card->dev->dev_addr[2], card->dev->dev_addr[3], |
| 5949 | card->dev->dev_addr[4], card->dev->dev_addr[5], |
| 5950 | card->dev->name); |
| 5951 | } |
| 5952 | return 0; |
| 5953 | } |
| 5954 | |
| 5955 | static int |
| 5956 | qeth_layer2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 5957 | { |
| 5958 | QETH_DBF_TEXT(trace, 2, "L2Setmac"); |
| 5959 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, |
| 5960 | qeth_layer2_send_setmac_cb); |
| 5961 | } |
| 5962 | |
| 5963 | static int |
| 5964 | qeth_layer2_send_delmac_cb(struct qeth_card *card, |
| 5965 | struct qeth_reply *reply, |
| 5966 | unsigned long data) |
| 5967 | { |
| 5968 | struct qeth_ipa_cmd *cmd; |
| 5969 | |
| 5970 | QETH_DBF_TEXT(trace, 2, "L2Dmaccb"); |
| 5971 | cmd = (struct qeth_ipa_cmd *) data; |
| 5972 | if (cmd->hdr.return_code) { |
| 5973 | PRINT_WARN("Error in deregistering MAC address on " \ |
| 5974 | "device %s: x%x\n", CARD_BUS_ID(card), |
| 5975 | cmd->hdr.return_code); |
| 5976 | QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code); |
| 5977 | cmd->hdr.return_code = -EIO; |
| 5978 | return 0; |
| 5979 | } |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5980 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | |
| 5982 | return 0; |
| 5983 | } |
| 5984 | static int |
| 5985 | qeth_layer2_send_delmac(struct qeth_card *card, __u8 *mac) |
| 5986 | { |
| 5987 | QETH_DBF_TEXT(trace, 2, "L2Delmac"); |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 5988 | if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | return 0; |
| 5990 | return qeth_layer2_send_setdelmac(card, mac, IPA_CMD_DELVMAC, |
| 5991 | qeth_layer2_send_delmac_cb); |
| 5992 | } |
| 5993 | |
| 5994 | static int |
| 5995 | qeth_layer2_set_mac_address(struct net_device *dev, void *p) |
| 5996 | { |
| 5997 | struct sockaddr *addr = p; |
| 5998 | struct qeth_card *card; |
| 5999 | int rc = 0; |
| 6000 | |
| 6001 | QETH_DBF_TEXT(trace, 3, "setmac"); |
| 6002 | |
| 6003 | if (qeth_verify_dev(dev) != QETH_REAL_CARD) { |
| 6004 | QETH_DBF_TEXT(trace, 3, "setmcINV"); |
| 6005 | return -EOPNOTSUPP; |
| 6006 | } |
| 6007 | card = (struct qeth_card *) dev->priv; |
| 6008 | |
| 6009 | if (!card->options.layer2) { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6010 | PRINT_WARN("Setting MAC address on %s is not supported " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | "in Layer 3 mode.\n", dev->name); |
| 6012 | QETH_DBF_TEXT(trace, 3, "setmcLY3"); |
| 6013 | return -EOPNOTSUPP; |
| 6014 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6015 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 6016 | PRINT_WARN("Setting MAC address on %s is not supported.\n", |
| 6017 | dev->name); |
| 6018 | QETH_DBF_TEXT(trace, 3, "setmcOSN"); |
| 6019 | return -EOPNOTSUPP; |
| 6020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6021 | QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card)); |
| 6022 | QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN); |
| 6023 | rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]); |
| 6024 | if (!rc) |
| 6025 | rc = qeth_layer2_send_setmac(card, addr->sa_data); |
| 6026 | return rc; |
| 6027 | } |
| 6028 | |
| 6029 | static void |
| 6030 | qeth_fill_ipacmd_header(struct qeth_card *card, struct qeth_ipa_cmd *cmd, |
| 6031 | __u8 command, enum qeth_prot_versions prot) |
| 6032 | { |
| 6033 | memset(cmd, 0, sizeof (struct qeth_ipa_cmd)); |
| 6034 | cmd->hdr.command = command; |
| 6035 | cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST; |
| 6036 | cmd->hdr.seqno = card->seqno.ipa; |
| 6037 | cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type); |
| 6038 | cmd->hdr.rel_adapter_no = (__u8) card->info.portno; |
| 6039 | if (card->options.layer2) |
| 6040 | cmd->hdr.prim_version_no = 2; |
| 6041 | else |
| 6042 | cmd->hdr.prim_version_no = 1; |
| 6043 | cmd->hdr.param_count = 1; |
| 6044 | cmd->hdr.prot_version = prot; |
| 6045 | cmd->hdr.ipa_supported = 0; |
| 6046 | cmd->hdr.ipa_enabled = 0; |
| 6047 | } |
| 6048 | |
| 6049 | static struct qeth_cmd_buffer * |
| 6050 | qeth_get_ipacmd_buffer(struct qeth_card *card, enum qeth_ipa_cmds ipacmd, |
| 6051 | enum qeth_prot_versions prot) |
| 6052 | { |
| 6053 | struct qeth_cmd_buffer *iob; |
| 6054 | struct qeth_ipa_cmd *cmd; |
| 6055 | |
| 6056 | iob = qeth_wait_for_buffer(&card->write); |
| 6057 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6058 | qeth_fill_ipacmd_header(card, cmd, ipacmd, prot); |
| 6059 | |
| 6060 | return iob; |
| 6061 | } |
| 6062 | |
| 6063 | static int |
| 6064 | qeth_send_setdelmc(struct qeth_card *card, struct qeth_ipaddr *addr, int ipacmd) |
| 6065 | { |
| 6066 | int rc; |
| 6067 | struct qeth_cmd_buffer *iob; |
| 6068 | struct qeth_ipa_cmd *cmd; |
| 6069 | |
| 6070 | QETH_DBF_TEXT(trace,4,"setdelmc"); |
| 6071 | |
| 6072 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
| 6073 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6074 | memcpy(&cmd->data.setdelipm.mac,addr->mac, OSA_ADDR_LEN); |
| 6075 | if (addr->proto == QETH_PROT_IPV6) |
| 6076 | memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr, |
| 6077 | sizeof(struct in6_addr)); |
| 6078 | else |
| 6079 | memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr,4); |
| 6080 | |
| 6081 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6082 | |
| 6083 | return rc; |
| 6084 | } |
| 6085 | static inline void |
| 6086 | qeth_fill_netmask(u8 *netmask, unsigned int len) |
| 6087 | { |
| 6088 | int i,j; |
| 6089 | for (i=0;i<16;i++) { |
| 6090 | j=(len)-(i*8); |
| 6091 | if (j >= 8) |
| 6092 | netmask[i] = 0xff; |
| 6093 | else if (j > 0) |
| 6094 | netmask[i] = (u8)(0xFF00>>j); |
| 6095 | else |
| 6096 | netmask[i] = 0; |
| 6097 | } |
| 6098 | } |
| 6099 | |
| 6100 | static int |
| 6101 | qeth_send_setdelip(struct qeth_card *card, struct qeth_ipaddr *addr, |
| 6102 | int ipacmd, unsigned int flags) |
| 6103 | { |
| 6104 | int rc; |
| 6105 | struct qeth_cmd_buffer *iob; |
| 6106 | struct qeth_ipa_cmd *cmd; |
| 6107 | __u8 netmask[16]; |
| 6108 | |
| 6109 | QETH_DBF_TEXT(trace,4,"setdelip"); |
| 6110 | QETH_DBF_TEXT_(trace,4,"flags%02X", flags); |
| 6111 | |
| 6112 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
| 6113 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6114 | if (addr->proto == QETH_PROT_IPV6) { |
| 6115 | memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr, |
| 6116 | sizeof(struct in6_addr)); |
| 6117 | qeth_fill_netmask(netmask,addr->u.a6.pfxlen); |
| 6118 | memcpy(cmd->data.setdelip6.mask, netmask, |
| 6119 | sizeof(struct in6_addr)); |
| 6120 | cmd->data.setdelip6.flags = flags; |
| 6121 | } else { |
| 6122 | memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4); |
| 6123 | memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4); |
| 6124 | cmd->data.setdelip4.flags = flags; |
| 6125 | } |
| 6126 | |
| 6127 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6128 | |
| 6129 | return rc; |
| 6130 | } |
| 6131 | |
| 6132 | static int |
| 6133 | qeth_layer2_register_addr_entry(struct qeth_card *card, |
| 6134 | struct qeth_ipaddr *addr) |
| 6135 | { |
| 6136 | if (!addr->is_multicast) |
| 6137 | return 0; |
| 6138 | QETH_DBF_TEXT(trace, 2, "setgmac"); |
| 6139 | QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN); |
| 6140 | return qeth_layer2_send_setgroupmac(card, &addr->mac[0]); |
| 6141 | } |
| 6142 | |
| 6143 | static int |
| 6144 | qeth_layer2_deregister_addr_entry(struct qeth_card *card, |
| 6145 | struct qeth_ipaddr *addr) |
| 6146 | { |
| 6147 | if (!addr->is_multicast) |
| 6148 | return 0; |
| 6149 | QETH_DBF_TEXT(trace, 2, "delgmac"); |
| 6150 | QETH_DBF_HEX(trace,3,&addr->mac[0],OSA_ADDR_LEN); |
| 6151 | return qeth_layer2_send_delgroupmac(card, &addr->mac[0]); |
| 6152 | } |
| 6153 | |
| 6154 | static int |
| 6155 | qeth_layer3_register_addr_entry(struct qeth_card *card, |
| 6156 | struct qeth_ipaddr *addr) |
| 6157 | { |
| 6158 | char buf[50]; |
| 6159 | int rc; |
| 6160 | int cnt = 3; |
| 6161 | |
| 6162 | if (addr->proto == QETH_PROT_IPV4) { |
| 6163 | QETH_DBF_TEXT(trace, 2,"setaddr4"); |
| 6164 | QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int)); |
| 6165 | } else if (addr->proto == QETH_PROT_IPV6) { |
| 6166 | QETH_DBF_TEXT(trace, 2, "setaddr6"); |
| 6167 | QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8); |
| 6168 | QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8); |
| 6169 | } else { |
| 6170 | QETH_DBF_TEXT(trace, 2, "setaddr?"); |
| 6171 | QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr)); |
| 6172 | } |
| 6173 | do { |
| 6174 | if (addr->is_multicast) |
| 6175 | rc = qeth_send_setdelmc(card, addr, IPA_CMD_SETIPM); |
| 6176 | else |
| 6177 | rc = qeth_send_setdelip(card, addr, IPA_CMD_SETIP, |
| 6178 | addr->set_flags); |
| 6179 | if (rc) |
| 6180 | QETH_DBF_TEXT(trace, 2, "failed"); |
| 6181 | } while ((--cnt > 0) && rc); |
| 6182 | if (rc){ |
| 6183 | QETH_DBF_TEXT(trace, 2, "FAILED"); |
| 6184 | qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
| 6185 | PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n", |
| 6186 | buf, rc, rc); |
| 6187 | } |
| 6188 | return rc; |
| 6189 | } |
| 6190 | |
| 6191 | static int |
| 6192 | qeth_layer3_deregister_addr_entry(struct qeth_card *card, |
| 6193 | struct qeth_ipaddr *addr) |
| 6194 | { |
| 6195 | //char buf[50]; |
| 6196 | int rc; |
| 6197 | |
| 6198 | if (addr->proto == QETH_PROT_IPV4) { |
| 6199 | QETH_DBF_TEXT(trace, 2,"deladdr4"); |
| 6200 | QETH_DBF_HEX(trace, 3, &addr->u.a4.addr, sizeof(int)); |
| 6201 | } else if (addr->proto == QETH_PROT_IPV6) { |
| 6202 | QETH_DBF_TEXT(trace, 2, "deladdr6"); |
| 6203 | QETH_DBF_HEX(trace,3,&addr->u.a6.addr,8); |
| 6204 | QETH_DBF_HEX(trace,3,((char *)&addr->u.a6.addr)+8,8); |
| 6205 | } else { |
| 6206 | QETH_DBF_TEXT(trace, 2, "deladdr?"); |
| 6207 | QETH_DBF_HEX(trace, 3, addr, sizeof(struct qeth_ipaddr)); |
| 6208 | } |
| 6209 | if (addr->is_multicast) |
| 6210 | rc = qeth_send_setdelmc(card, addr, IPA_CMD_DELIPM); |
| 6211 | else |
| 6212 | rc = qeth_send_setdelip(card, addr, IPA_CMD_DELIP, |
| 6213 | addr->del_flags); |
| 6214 | if (rc) { |
| 6215 | QETH_DBF_TEXT(trace, 2, "failed"); |
| 6216 | /* TODO: re-activate this warning as soon as we have a |
| 6217 | * clean mirco code |
| 6218 | qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
| 6219 | PRINT_WARN("Could not deregister IP address %s (rc=%x)\n", |
| 6220 | buf, rc); |
| 6221 | */ |
| 6222 | } |
| 6223 | return rc; |
| 6224 | } |
| 6225 | |
| 6226 | static int |
| 6227 | qeth_register_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 6228 | { |
| 6229 | if (card->options.layer2) |
| 6230 | return qeth_layer2_register_addr_entry(card, addr); |
| 6231 | |
| 6232 | return qeth_layer3_register_addr_entry(card, addr); |
| 6233 | } |
| 6234 | |
| 6235 | static int |
| 6236 | qeth_deregister_addr_entry(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 6237 | { |
| 6238 | if (card->options.layer2) |
| 6239 | return qeth_layer2_deregister_addr_entry(card, addr); |
| 6240 | |
| 6241 | return qeth_layer3_deregister_addr_entry(card, addr); |
| 6242 | } |
| 6243 | |
| 6244 | static u32 |
| 6245 | qeth_ethtool_get_tx_csum(struct net_device *dev) |
| 6246 | { |
| 6247 | /* We may need to say that we support tx csum offload if |
| 6248 | * we do EDDP or TSO. There are discussions going on to |
| 6249 | * enforce rules in the stack and in ethtool that make |
| 6250 | * SG and TSO depend on HW_CSUM. At the moment there are |
| 6251 | * no such rules.... |
| 6252 | * If we say yes here, we have to checksum outbound packets |
| 6253 | * any time. */ |
| 6254 | return 0; |
| 6255 | } |
| 6256 | |
| 6257 | static int |
| 6258 | qeth_ethtool_set_tx_csum(struct net_device *dev, u32 data) |
| 6259 | { |
| 6260 | return -EINVAL; |
| 6261 | } |
| 6262 | |
| 6263 | static u32 |
| 6264 | qeth_ethtool_get_rx_csum(struct net_device *dev) |
| 6265 | { |
| 6266 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6267 | |
| 6268 | return (card->options.checksum_type == HW_CHECKSUMMING); |
| 6269 | } |
| 6270 | |
| 6271 | static int |
| 6272 | qeth_ethtool_set_rx_csum(struct net_device *dev, u32 data) |
| 6273 | { |
| 6274 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6275 | |
| 6276 | if ((card->state != CARD_STATE_DOWN) && |
| 6277 | (card->state != CARD_STATE_RECOVER)) |
| 6278 | return -EPERM; |
| 6279 | if (data) |
| 6280 | card->options.checksum_type = HW_CHECKSUMMING; |
| 6281 | else |
| 6282 | card->options.checksum_type = SW_CHECKSUMMING; |
| 6283 | return 0; |
| 6284 | } |
| 6285 | |
| 6286 | static u32 |
| 6287 | qeth_ethtool_get_sg(struct net_device *dev) |
| 6288 | { |
| 6289 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6290 | |
| 6291 | return ((card->options.large_send != QETH_LARGE_SEND_NO) && |
| 6292 | (dev->features & NETIF_F_SG)); |
| 6293 | } |
| 6294 | |
| 6295 | static int |
| 6296 | qeth_ethtool_set_sg(struct net_device *dev, u32 data) |
| 6297 | { |
| 6298 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6299 | |
| 6300 | if (data) { |
| 6301 | if (card->options.large_send != QETH_LARGE_SEND_NO) |
| 6302 | dev->features |= NETIF_F_SG; |
| 6303 | else { |
| 6304 | dev->features &= ~NETIF_F_SG; |
| 6305 | return -EINVAL; |
| 6306 | } |
| 6307 | } else |
| 6308 | dev->features &= ~NETIF_F_SG; |
| 6309 | return 0; |
| 6310 | } |
| 6311 | |
| 6312 | static u32 |
| 6313 | qeth_ethtool_get_tso(struct net_device *dev) |
| 6314 | { |
| 6315 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6316 | |
| 6317 | return ((card->options.large_send != QETH_LARGE_SEND_NO) && |
| 6318 | (dev->features & NETIF_F_TSO)); |
| 6319 | } |
| 6320 | |
| 6321 | static int |
| 6322 | qeth_ethtool_set_tso(struct net_device *dev, u32 data) |
| 6323 | { |
| 6324 | struct qeth_card *card = (struct qeth_card *)dev->priv; |
| 6325 | |
| 6326 | if (data) { |
| 6327 | if (card->options.large_send != QETH_LARGE_SEND_NO) |
| 6328 | dev->features |= NETIF_F_TSO; |
| 6329 | else { |
| 6330 | dev->features &= ~NETIF_F_TSO; |
| 6331 | return -EINVAL; |
| 6332 | } |
| 6333 | } else |
| 6334 | dev->features &= ~NETIF_F_TSO; |
| 6335 | return 0; |
| 6336 | } |
| 6337 | |
| 6338 | static struct ethtool_ops qeth_ethtool_ops = { |
| 6339 | .get_tx_csum = qeth_ethtool_get_tx_csum, |
| 6340 | .set_tx_csum = qeth_ethtool_set_tx_csum, |
| 6341 | .get_rx_csum = qeth_ethtool_get_rx_csum, |
| 6342 | .set_rx_csum = qeth_ethtool_set_rx_csum, |
| 6343 | .get_sg = qeth_ethtool_get_sg, |
| 6344 | .set_sg = qeth_ethtool_set_sg, |
| 6345 | .get_tso = qeth_ethtool_get_tso, |
| 6346 | .set_tso = qeth_ethtool_set_tso, |
| 6347 | }; |
| 6348 | |
| 6349 | static int |
| 6350 | qeth_netdev_init(struct net_device *dev) |
| 6351 | { |
| 6352 | struct qeth_card *card; |
| 6353 | |
| 6354 | card = (struct qeth_card *) dev->priv; |
| 6355 | |
| 6356 | QETH_DBF_TEXT(trace,3,"initdev"); |
| 6357 | |
| 6358 | dev->tx_timeout = &qeth_tx_timeout; |
| 6359 | dev->watchdog_timeo = QETH_TX_TIMEOUT; |
| 6360 | dev->open = qeth_open; |
| 6361 | dev->stop = qeth_stop; |
| 6362 | dev->hard_start_xmit = qeth_hard_start_xmit; |
| 6363 | dev->do_ioctl = qeth_do_ioctl; |
| 6364 | dev->get_stats = qeth_get_stats; |
| 6365 | dev->change_mtu = qeth_change_mtu; |
| 6366 | dev->neigh_setup = qeth_neigh_setup; |
| 6367 | dev->set_multicast_list = qeth_set_multicast_list; |
| 6368 | #ifdef CONFIG_QETH_VLAN |
| 6369 | dev->vlan_rx_register = qeth_vlan_rx_register; |
| 6370 | dev->vlan_rx_kill_vid = qeth_vlan_rx_kill_vid; |
| 6371 | dev->vlan_rx_add_vid = qeth_vlan_rx_add_vid; |
| 6372 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | if (qeth_get_netdev_flags(card) & IFF_NOARP) { |
| 6374 | dev->rebuild_header = NULL; |
| 6375 | dev->hard_header = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | dev->header_cache_update = NULL; |
| 6377 | dev->hard_header_cache = NULL; |
| 6378 | } |
| 6379 | #ifdef CONFIG_QETH_IPV6 |
| 6380 | /*IPv6 address autoconfiguration stuff*/ |
| 6381 | if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD)) |
| 6382 | card->dev->dev_id = card->info.unique_id & 0xffff; |
| 6383 | #endif |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6384 | if (card->options.fake_ll && |
Ursula Braun | ba1aa08 | 2006-05-24 09:51:13 +0200 | [diff] [blame] | 6385 | (qeth_get_netdev_flags(card) & IFF_NOARP)) |
| 6386 | dev->hard_header = qeth_fake_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6387 | dev->hard_header_parse = NULL; |
| 6388 | dev->set_mac_address = qeth_layer2_set_mac_address; |
| 6389 | dev->flags |= qeth_get_netdev_flags(card); |
| 6390 | if ((card->options.fake_broadcast) || |
| 6391 | (card->info.broadcast_capable)) |
| 6392 | dev->flags |= IFF_BROADCAST; |
| 6393 | dev->hard_header_len = |
| 6394 | qeth_get_hlen(card->info.link_type) + card->options.add_hhlen; |
| 6395 | dev->addr_len = OSA_ADDR_LEN; |
| 6396 | dev->mtu = card->info.initial_mtu; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6397 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 6398 | SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | SET_MODULE_OWNER(dev); |
| 6400 | return 0; |
| 6401 | } |
| 6402 | |
| 6403 | static void |
| 6404 | qeth_init_func_level(struct qeth_card *card) |
| 6405 | { |
| 6406 | if (card->ipato.enabled) { |
| 6407 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 6408 | card->info.func_level = |
| 6409 | QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT; |
| 6410 | else |
| 6411 | card->info.func_level = |
| 6412 | QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT; |
| 6413 | } else { |
| 6414 | if (card->info.type == QETH_CARD_TYPE_IQD) |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6415 | /*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] | 6416 | card->info.func_level = |
| 6417 | QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT; |
| 6418 | else |
| 6419 | card->info.func_level = |
| 6420 | QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT; |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | /** |
| 6425 | * hardsetup card, initialize MPC and QDIO stuff |
| 6426 | */ |
| 6427 | static int |
| 6428 | qeth_hardsetup_card(struct qeth_card *card) |
| 6429 | { |
| 6430 | int retries = 3; |
| 6431 | int rc; |
| 6432 | |
| 6433 | QETH_DBF_TEXT(setup, 2, "hrdsetup"); |
| 6434 | |
| 6435 | retry: |
| 6436 | if (retries < 3){ |
| 6437 | PRINT_WARN("Retrying to do IDX activates.\n"); |
| 6438 | ccw_device_set_offline(CARD_DDEV(card)); |
| 6439 | ccw_device_set_offline(CARD_WDEV(card)); |
| 6440 | ccw_device_set_offline(CARD_RDEV(card)); |
| 6441 | ccw_device_set_online(CARD_RDEV(card)); |
| 6442 | ccw_device_set_online(CARD_WDEV(card)); |
| 6443 | ccw_device_set_online(CARD_DDEV(card)); |
| 6444 | } |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6445 | 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] | 6446 | if (rc == -ERESTARTSYS) { |
| 6447 | QETH_DBF_TEXT(setup, 2, "break1"); |
| 6448 | return rc; |
| 6449 | } else if (rc) { |
| 6450 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 6451 | if (--retries < 0) |
| 6452 | goto out; |
| 6453 | else |
| 6454 | goto retry; |
| 6455 | } |
| 6456 | if ((rc = qeth_get_unitaddr(card))){ |
| 6457 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 6458 | return rc; |
| 6459 | } |
| 6460 | qeth_init_tokens(card); |
| 6461 | qeth_init_func_level(card); |
| 6462 | rc = qeth_idx_activate_channel(&card->read, qeth_idx_read_cb); |
| 6463 | if (rc == -ERESTARTSYS) { |
| 6464 | QETH_DBF_TEXT(setup, 2, "break2"); |
| 6465 | return rc; |
| 6466 | } else if (rc) { |
| 6467 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 6468 | if (--retries < 0) |
| 6469 | goto out; |
| 6470 | else |
| 6471 | goto retry; |
| 6472 | } |
| 6473 | rc = qeth_idx_activate_channel(&card->write, qeth_idx_write_cb); |
| 6474 | if (rc == -ERESTARTSYS) { |
| 6475 | QETH_DBF_TEXT(setup, 2, "break3"); |
| 6476 | return rc; |
| 6477 | } else if (rc) { |
| 6478 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 6479 | if (--retries < 0) |
| 6480 | goto out; |
| 6481 | else |
| 6482 | goto retry; |
| 6483 | } |
| 6484 | if ((rc = qeth_mpc_initialize(card))){ |
| 6485 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 6486 | goto out; |
| 6487 | } |
| 6488 | /*network device will be recovered*/ |
| 6489 | if (card->dev) { |
| 6490 | card->dev->hard_header = card->orig_hard_header; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6491 | if (card->options.fake_ll && |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 6492 | (qeth_get_netdev_flags(card) & IFF_NOARP)) |
| 6493 | card->dev->hard_header = qeth_fake_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6494 | return 0; |
| 6495 | } |
| 6496 | /* at first set_online allocate netdev */ |
| 6497 | card->dev = qeth_get_netdevice(card->info.type, |
| 6498 | card->info.link_type); |
| 6499 | if (!card->dev){ |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 6500 | qeth_qdio_clear_card(card, card->info.type != |
| 6501 | QETH_CARD_TYPE_IQD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6502 | rc = -ENODEV; |
| 6503 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 6504 | goto out; |
| 6505 | } |
| 6506 | card->dev->priv = card; |
| 6507 | card->orig_hard_header = card->dev->hard_header; |
| 6508 | card->dev->type = qeth_get_arphdr_type(card->info.type, |
| 6509 | card->info.link_type); |
| 6510 | card->dev->init = qeth_netdev_init; |
| 6511 | return 0; |
| 6512 | out: |
| 6513 | PRINT_ERR("Initialization in hardsetup failed! rc=%d\n", rc); |
| 6514 | return rc; |
| 6515 | } |
| 6516 | |
| 6517 | static int |
| 6518 | qeth_default_setassparms_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6519 | unsigned long data) |
| 6520 | { |
| 6521 | struct qeth_ipa_cmd *cmd; |
| 6522 | |
| 6523 | QETH_DBF_TEXT(trace,4,"defadpcb"); |
| 6524 | |
| 6525 | cmd = (struct qeth_ipa_cmd *) data; |
| 6526 | if (cmd->hdr.return_code == 0){ |
| 6527 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
| 6528 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) |
| 6529 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6530 | #ifdef CONFIG_QETH_IPV6 |
| 6531 | if (cmd->hdr.prot_version == QETH_PROT_IPV6) |
| 6532 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6533 | #endif |
| 6534 | } |
| 6535 | if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM && |
| 6536 | cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) { |
| 6537 | card->info.csum_mask = cmd->data.setassparms.data.flags_32bit; |
| 6538 | QETH_DBF_TEXT_(trace, 3, "csum:%d", card->info.csum_mask); |
| 6539 | } |
| 6540 | return 0; |
| 6541 | } |
| 6542 | |
| 6543 | static int |
| 6544 | qeth_default_setadapterparms_cb(struct qeth_card *card, |
| 6545 | struct qeth_reply *reply, |
| 6546 | unsigned long data) |
| 6547 | { |
| 6548 | struct qeth_ipa_cmd *cmd; |
| 6549 | |
| 6550 | QETH_DBF_TEXT(trace,4,"defadpcb"); |
| 6551 | |
| 6552 | cmd = (struct qeth_ipa_cmd *) data; |
| 6553 | if (cmd->hdr.return_code == 0) |
| 6554 | cmd->hdr.return_code = cmd->data.setadapterparms.hdr.return_code; |
| 6555 | return 0; |
| 6556 | } |
| 6557 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 6558 | |
| 6559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | static int |
| 6561 | qeth_query_setadapterparms_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6562 | unsigned long data) |
| 6563 | { |
| 6564 | struct qeth_ipa_cmd *cmd; |
| 6565 | |
| 6566 | QETH_DBF_TEXT(trace,3,"quyadpcb"); |
| 6567 | |
| 6568 | cmd = (struct qeth_ipa_cmd *) data; |
| 6569 | if (cmd->data.setadapterparms.data.query_cmds_supp.lan_type & 0x7f) |
| 6570 | card->info.link_type = |
| 6571 | cmd->data.setadapterparms.data.query_cmds_supp.lan_type; |
| 6572 | card->options.adp.supported_funcs = |
| 6573 | cmd->data.setadapterparms.data.query_cmds_supp.supported_cmds; |
| 6574 | return qeth_default_setadapterparms_cb(card, reply, (unsigned long)cmd); |
| 6575 | } |
| 6576 | |
| 6577 | static int |
| 6578 | qeth_query_setadapterparms(struct qeth_card *card) |
| 6579 | { |
| 6580 | int rc; |
| 6581 | struct qeth_cmd_buffer *iob; |
| 6582 | |
| 6583 | QETH_DBF_TEXT(trace,3,"queryadp"); |
| 6584 | iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_COMMANDS_SUPPORTED, |
| 6585 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6586 | rc = qeth_send_ipa_cmd(card, iob, qeth_query_setadapterparms_cb, NULL); |
| 6587 | return rc; |
| 6588 | } |
| 6589 | |
| 6590 | static int |
| 6591 | qeth_setadpparms_change_macaddr_cb(struct qeth_card *card, |
| 6592 | struct qeth_reply *reply, |
| 6593 | unsigned long data) |
| 6594 | { |
| 6595 | struct qeth_ipa_cmd *cmd; |
| 6596 | |
| 6597 | QETH_DBF_TEXT(trace,4,"chgmaccb"); |
| 6598 | |
| 6599 | cmd = (struct qeth_ipa_cmd *) data; |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6600 | if (!card->options.layer2 || card->info.guestlan || |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 6601 | !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) { |
Frank Pavlic | e08d88c | 2005-11-10 13:51:17 +0100 | [diff] [blame] | 6602 | memcpy(card->dev->dev_addr, |
| 6603 | &cmd->data.setadapterparms.data.change_addr.addr, |
| 6604 | OSA_ADDR_LEN); |
| 6605 | card->info.mac_bits |= QETH_LAYER2_MAC_READ; |
| 6606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6607 | qeth_default_setadapterparms_cb(card, reply, (unsigned long) cmd); |
| 6608 | return 0; |
| 6609 | } |
| 6610 | |
| 6611 | static int |
| 6612 | qeth_setadpparms_change_macaddr(struct qeth_card *card) |
| 6613 | { |
| 6614 | int rc; |
| 6615 | struct qeth_cmd_buffer *iob; |
| 6616 | struct qeth_ipa_cmd *cmd; |
| 6617 | |
| 6618 | QETH_DBF_TEXT(trace,4,"chgmac"); |
| 6619 | |
| 6620 | iob = qeth_get_adapter_cmd(card,IPA_SETADP_ALTER_MAC_ADDRESS, |
| 6621 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6622 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6623 | cmd->data.setadapterparms.data.change_addr.cmd = CHANGE_ADDR_READ_MAC; |
| 6624 | cmd->data.setadapterparms.data.change_addr.addr_size = OSA_ADDR_LEN; |
| 6625 | memcpy(&cmd->data.setadapterparms.data.change_addr.addr, |
| 6626 | card->dev->dev_addr, OSA_ADDR_LEN); |
| 6627 | rc = qeth_send_ipa_cmd(card, iob, qeth_setadpparms_change_macaddr_cb, |
| 6628 | NULL); |
| 6629 | return rc; |
| 6630 | } |
| 6631 | |
| 6632 | static int |
| 6633 | qeth_send_setadp_mode(struct qeth_card *card, __u32 command, __u32 mode) |
| 6634 | { |
| 6635 | int rc; |
| 6636 | struct qeth_cmd_buffer *iob; |
| 6637 | struct qeth_ipa_cmd *cmd; |
| 6638 | |
| 6639 | QETH_DBF_TEXT(trace,4,"adpmode"); |
| 6640 | |
| 6641 | iob = qeth_get_adapter_cmd(card, command, |
| 6642 | sizeof(struct qeth_ipacmd_setadpparms)); |
| 6643 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6644 | cmd->data.setadapterparms.data.mode = mode; |
| 6645 | rc = qeth_send_ipa_cmd(card, iob, qeth_default_setadapterparms_cb, |
| 6646 | NULL); |
| 6647 | return rc; |
| 6648 | } |
| 6649 | |
| 6650 | static inline int |
| 6651 | qeth_setadapter_hstr(struct qeth_card *card) |
| 6652 | { |
| 6653 | int rc; |
| 6654 | |
| 6655 | QETH_DBF_TEXT(trace,4,"adphstr"); |
| 6656 | |
| 6657 | if (qeth_adp_supported(card,IPA_SETADP_SET_BROADCAST_MODE)) { |
| 6658 | rc = qeth_send_setadp_mode(card, IPA_SETADP_SET_BROADCAST_MODE, |
| 6659 | card->options.broadcast_mode); |
| 6660 | if (rc) |
| 6661 | PRINT_WARN("couldn't set broadcast mode on " |
| 6662 | "device %s: x%x\n", |
| 6663 | CARD_BUS_ID(card), rc); |
| 6664 | rc = qeth_send_setadp_mode(card, IPA_SETADP_ALTER_MAC_ADDRESS, |
| 6665 | card->options.macaddr_mode); |
| 6666 | if (rc) |
| 6667 | PRINT_WARN("couldn't set macaddr mode on " |
| 6668 | "device %s: x%x\n", CARD_BUS_ID(card), rc); |
| 6669 | return rc; |
| 6670 | } |
| 6671 | if (card->options.broadcast_mode == QETH_TR_BROADCAST_LOCAL) |
| 6672 | PRINT_WARN("set adapter parameters not available " |
| 6673 | "to set broadcast mode, using ALLRINGS " |
| 6674 | "on device %s:\n", CARD_BUS_ID(card)); |
| 6675 | if (card->options.macaddr_mode == QETH_TR_MACADDR_CANONICAL) |
| 6676 | PRINT_WARN("set adapter parameters not available " |
| 6677 | "to set macaddr mode, using NONCANONICAL " |
| 6678 | "on device %s:\n", CARD_BUS_ID(card)); |
| 6679 | return 0; |
| 6680 | } |
| 6681 | |
| 6682 | static int |
| 6683 | qeth_setadapter_parms(struct qeth_card *card) |
| 6684 | { |
| 6685 | int rc; |
| 6686 | |
| 6687 | QETH_DBF_TEXT(setup, 2, "setadprm"); |
| 6688 | |
| 6689 | if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)){ |
| 6690 | PRINT_WARN("set adapter parameters not supported " |
| 6691 | "on device %s.\n", |
| 6692 | CARD_BUS_ID(card)); |
| 6693 | QETH_DBF_TEXT(setup, 2, " notsupp"); |
| 6694 | return 0; |
| 6695 | } |
| 6696 | rc = qeth_query_setadapterparms(card); |
| 6697 | if (rc) { |
| 6698 | PRINT_WARN("couldn't set adapter parameters on device %s: " |
| 6699 | "x%x\n", CARD_BUS_ID(card), rc); |
| 6700 | return rc; |
| 6701 | } |
| 6702 | if (qeth_adp_supported(card,IPA_SETADP_ALTER_MAC_ADDRESS)) { |
| 6703 | rc = qeth_setadpparms_change_macaddr(card); |
| 6704 | if (rc) |
| 6705 | PRINT_WARN("couldn't get MAC address on " |
| 6706 | "device %s: x%x\n", |
| 6707 | CARD_BUS_ID(card), rc); |
| 6708 | } |
| 6709 | |
| 6710 | if ((card->info.link_type == QETH_LINK_TYPE_HSTR) || |
| 6711 | (card->info.link_type == QETH_LINK_TYPE_LANE_TR)) |
| 6712 | rc = qeth_setadapter_hstr(card); |
| 6713 | |
| 6714 | return rc; |
| 6715 | } |
| 6716 | |
| 6717 | static int |
| 6718 | qeth_layer2_initialize(struct qeth_card *card) |
| 6719 | { |
| 6720 | int rc = 0; |
| 6721 | |
| 6722 | |
| 6723 | QETH_DBF_TEXT(setup, 2, "doL2init"); |
| 6724 | QETH_DBF_TEXT_(setup, 2, "doL2%s", CARD_BUS_ID(card)); |
| 6725 | |
Frank Pavlic | 6c951b9 | 2005-11-10 13:51:25 +0100 | [diff] [blame] | 6726 | rc = qeth_query_setadapterparms(card); |
| 6727 | if (rc) { |
| 6728 | PRINT_WARN("could not query adapter parameters on device %s: " |
| 6729 | "x%x\n", CARD_BUS_ID(card), rc); |
| 6730 | } |
| 6731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6732 | rc = qeth_setadpparms_change_macaddr(card); |
| 6733 | if (rc) { |
| 6734 | PRINT_WARN("couldn't get MAC address on " |
| 6735 | "device %s: x%x\n", |
| 6736 | CARD_BUS_ID(card), rc); |
| 6737 | QETH_DBF_TEXT_(setup, 2,"1err%d",rc); |
| 6738 | return rc; |
| 6739 | } |
| 6740 | QETH_DBF_HEX(setup,2, card->dev->dev_addr, OSA_ADDR_LEN); |
| 6741 | |
| 6742 | rc = qeth_layer2_send_setmac(card, &card->dev->dev_addr[0]); |
| 6743 | if (rc) |
| 6744 | QETH_DBF_TEXT_(setup, 2,"2err%d",rc); |
| 6745 | return 0; |
| 6746 | } |
| 6747 | |
| 6748 | |
| 6749 | static int |
| 6750 | qeth_send_startstoplan(struct qeth_card *card, enum qeth_ipa_cmds ipacmd, |
| 6751 | enum qeth_prot_versions prot) |
| 6752 | { |
| 6753 | int rc; |
| 6754 | struct qeth_cmd_buffer *iob; |
| 6755 | |
| 6756 | iob = qeth_get_ipacmd_buffer(card,ipacmd,prot); |
| 6757 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 6758 | |
| 6759 | return rc; |
| 6760 | } |
| 6761 | |
| 6762 | static int |
| 6763 | qeth_send_startlan(struct qeth_card *card, enum qeth_prot_versions prot) |
| 6764 | { |
| 6765 | int rc; |
| 6766 | |
| 6767 | QETH_DBF_TEXT_(setup, 2, "strtlan%i", prot); |
| 6768 | |
| 6769 | rc = qeth_send_startstoplan(card, IPA_CMD_STARTLAN, prot); |
| 6770 | return rc; |
| 6771 | } |
| 6772 | |
| 6773 | static int |
| 6774 | qeth_send_stoplan(struct qeth_card *card) |
| 6775 | { |
| 6776 | int rc = 0; |
| 6777 | |
| 6778 | /* |
| 6779 | * TODO: according to the IPA format document page 14, |
| 6780 | * TCP/IP (we!) never issue a STOPLAN |
| 6781 | * is this right ?!? |
| 6782 | */ |
| 6783 | QETH_DBF_TEXT(trace, 2, "stoplan"); |
| 6784 | |
| 6785 | rc = qeth_send_startstoplan(card, IPA_CMD_STOPLAN, QETH_PROT_IPV4); |
| 6786 | return rc; |
| 6787 | } |
| 6788 | |
| 6789 | static int |
| 6790 | qeth_query_ipassists_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 6791 | unsigned long data) |
| 6792 | { |
| 6793 | struct qeth_ipa_cmd *cmd; |
| 6794 | |
| 6795 | QETH_DBF_TEXT(setup, 2, "qipasscb"); |
| 6796 | |
| 6797 | cmd = (struct qeth_ipa_cmd *) data; |
| 6798 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) { |
| 6799 | card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported; |
| 6800 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
Ursula Braun | 9123e0d | 2005-09-30 10:17:24 +0200 | [diff] [blame] | 6801 | /* Disable IPV6 support hard coded for Hipersockets */ |
| 6802 | if(card->info.type == QETH_CARD_TYPE_IQD) |
| 6803 | card->options.ipa4.supported_funcs &= ~IPA_IPV6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6804 | } else { |
| 6805 | #ifdef CONFIG_QETH_IPV6 |
| 6806 | card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported; |
| 6807 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 6808 | #endif |
| 6809 | } |
| 6810 | QETH_DBF_TEXT(setup, 2, "suppenbl"); |
| 6811 | QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_supported); |
| 6812 | QETH_DBF_TEXT_(setup, 2, "%x",cmd->hdr.ipa_enabled); |
| 6813 | return 0; |
| 6814 | } |
| 6815 | |
| 6816 | static int |
| 6817 | qeth_query_ipassists(struct qeth_card *card, enum qeth_prot_versions prot) |
| 6818 | { |
| 6819 | int rc; |
| 6820 | struct qeth_cmd_buffer *iob; |
| 6821 | |
| 6822 | QETH_DBF_TEXT_(setup, 2, "qipassi%i", prot); |
| 6823 | if (card->options.layer2) { |
| 6824 | QETH_DBF_TEXT(setup, 2, "noprmly2"); |
| 6825 | return -EPERM; |
| 6826 | } |
| 6827 | |
| 6828 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_QIPASSIST,prot); |
| 6829 | rc = qeth_send_ipa_cmd(card, iob, qeth_query_ipassists_cb, NULL); |
| 6830 | return rc; |
| 6831 | } |
| 6832 | |
| 6833 | static struct qeth_cmd_buffer * |
| 6834 | qeth_get_setassparms_cmd(struct qeth_card *card, enum qeth_ipa_funcs ipa_func, |
| 6835 | __u16 cmd_code, __u16 len, |
| 6836 | enum qeth_prot_versions prot) |
| 6837 | { |
| 6838 | struct qeth_cmd_buffer *iob; |
| 6839 | struct qeth_ipa_cmd *cmd; |
| 6840 | |
| 6841 | QETH_DBF_TEXT(trace,4,"getasscm"); |
| 6842 | iob = qeth_get_ipacmd_buffer(card,IPA_CMD_SETASSPARMS,prot); |
| 6843 | |
| 6844 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6845 | cmd->data.setassparms.hdr.assist_no = ipa_func; |
| 6846 | cmd->data.setassparms.hdr.length = 8 + len; |
| 6847 | cmd->data.setassparms.hdr.command_code = cmd_code; |
| 6848 | cmd->data.setassparms.hdr.return_code = 0; |
| 6849 | cmd->data.setassparms.hdr.seq_no = 0; |
| 6850 | |
| 6851 | return iob; |
| 6852 | } |
| 6853 | |
| 6854 | static int |
| 6855 | qeth_send_setassparms(struct qeth_card *card, struct qeth_cmd_buffer *iob, |
| 6856 | __u16 len, long data, |
| 6857 | int (*reply_cb) |
| 6858 | (struct qeth_card *,struct qeth_reply *,unsigned long), |
| 6859 | void *reply_param) |
| 6860 | { |
| 6861 | int rc; |
| 6862 | struct qeth_ipa_cmd *cmd; |
| 6863 | |
| 6864 | QETH_DBF_TEXT(trace,4,"sendassp"); |
| 6865 | |
| 6866 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 6867 | if (len <= sizeof(__u32)) |
| 6868 | cmd->data.setassparms.data.flags_32bit = (__u32) data; |
Frank Pavlic | 1380fee | 2006-03-22 16:03:41 +0100 | [diff] [blame] | 6869 | else /* (len > sizeof(__u32)) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6870 | memcpy(&cmd->data.setassparms.data, (void *) data, len); |
| 6871 | |
| 6872 | rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param); |
| 6873 | return rc; |
| 6874 | } |
| 6875 | |
| 6876 | #ifdef CONFIG_QETH_IPV6 |
| 6877 | static int |
| 6878 | qeth_send_simple_setassparms_ipv6(struct qeth_card *card, |
| 6879 | enum qeth_ipa_funcs ipa_func, __u16 cmd_code) |
| 6880 | |
| 6881 | { |
| 6882 | int rc; |
| 6883 | struct qeth_cmd_buffer *iob; |
| 6884 | |
| 6885 | QETH_DBF_TEXT(trace,4,"simassp6"); |
| 6886 | iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 6887 | 0, QETH_PROT_IPV6); |
| 6888 | rc = qeth_send_setassparms(card, iob, 0, 0, |
| 6889 | qeth_default_setassparms_cb, NULL); |
| 6890 | return rc; |
| 6891 | } |
| 6892 | #endif |
| 6893 | |
| 6894 | static int |
| 6895 | qeth_send_simple_setassparms(struct qeth_card *card, |
| 6896 | enum qeth_ipa_funcs ipa_func, |
| 6897 | __u16 cmd_code, long data) |
| 6898 | { |
| 6899 | int rc; |
| 6900 | int length = 0; |
| 6901 | struct qeth_cmd_buffer *iob; |
| 6902 | |
| 6903 | QETH_DBF_TEXT(trace,4,"simassp4"); |
| 6904 | if (data) |
| 6905 | length = sizeof(__u32); |
| 6906 | iob = qeth_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 6907 | length, QETH_PROT_IPV4); |
| 6908 | rc = qeth_send_setassparms(card, iob, length, data, |
| 6909 | qeth_default_setassparms_cb, NULL); |
| 6910 | return rc; |
| 6911 | } |
| 6912 | |
| 6913 | static inline int |
| 6914 | qeth_start_ipa_arp_processing(struct qeth_card *card) |
| 6915 | { |
| 6916 | int rc; |
| 6917 | |
| 6918 | QETH_DBF_TEXT(trace,3,"ipaarp"); |
| 6919 | |
| 6920 | if (!qeth_is_supported(card,IPA_ARP_PROCESSING)) { |
| 6921 | PRINT_WARN("ARP processing not supported " |
| 6922 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 6923 | return 0; |
| 6924 | } |
| 6925 | rc = qeth_send_simple_setassparms(card,IPA_ARP_PROCESSING, |
| 6926 | IPA_CMD_ASS_START, 0); |
| 6927 | if (rc) { |
| 6928 | PRINT_WARN("Could not start ARP processing " |
| 6929 | "assist on %s: 0x%x\n", |
| 6930 | QETH_CARD_IFNAME(card), rc); |
| 6931 | } |
| 6932 | return rc; |
| 6933 | } |
| 6934 | |
| 6935 | static int |
| 6936 | qeth_start_ipa_ip_fragmentation(struct qeth_card *card) |
| 6937 | { |
| 6938 | int rc; |
| 6939 | |
| 6940 | QETH_DBF_TEXT(trace,3,"ipaipfrg"); |
| 6941 | |
| 6942 | if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) { |
| 6943 | PRINT_INFO("Hardware IP fragmentation not supported on %s\n", |
| 6944 | QETH_CARD_IFNAME(card)); |
| 6945 | return -EOPNOTSUPP; |
| 6946 | } |
| 6947 | |
| 6948 | rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION, |
| 6949 | IPA_CMD_ASS_START, 0); |
| 6950 | if (rc) { |
| 6951 | PRINT_WARN("Could not start Hardware IP fragmentation " |
| 6952 | "assist on %s: 0x%x\n", |
| 6953 | QETH_CARD_IFNAME(card), rc); |
| 6954 | } else |
| 6955 | PRINT_INFO("Hardware IP fragmentation enabled \n"); |
| 6956 | return rc; |
| 6957 | } |
| 6958 | |
| 6959 | static int |
| 6960 | qeth_start_ipa_source_mac(struct qeth_card *card) |
| 6961 | { |
| 6962 | int rc; |
| 6963 | |
| 6964 | QETH_DBF_TEXT(trace,3,"stsrcmac"); |
| 6965 | |
| 6966 | if (!card->options.fake_ll) |
| 6967 | return -EOPNOTSUPP; |
| 6968 | |
| 6969 | if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { |
| 6970 | PRINT_INFO("Inbound source address not " |
| 6971 | "supported on %s\n", QETH_CARD_IFNAME(card)); |
| 6972 | return -EOPNOTSUPP; |
| 6973 | } |
| 6974 | |
| 6975 | rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC, |
| 6976 | IPA_CMD_ASS_START, 0); |
| 6977 | if (rc) |
| 6978 | PRINT_WARN("Could not start inbound source " |
| 6979 | "assist on %s: 0x%x\n", |
| 6980 | QETH_CARD_IFNAME(card), rc); |
| 6981 | return rc; |
| 6982 | } |
| 6983 | |
| 6984 | static int |
| 6985 | qeth_start_ipa_vlan(struct qeth_card *card) |
| 6986 | { |
| 6987 | int rc = 0; |
| 6988 | |
| 6989 | QETH_DBF_TEXT(trace,3,"strtvlan"); |
| 6990 | |
| 6991 | #ifdef CONFIG_QETH_VLAN |
| 6992 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) { |
| 6993 | PRINT_WARN("VLAN not supported on %s\n", QETH_CARD_IFNAME(card)); |
| 6994 | return -EOPNOTSUPP; |
| 6995 | } |
| 6996 | |
| 6997 | rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO, |
| 6998 | IPA_CMD_ASS_START,0); |
| 6999 | if (rc) { |
| 7000 | PRINT_WARN("Could not start vlan " |
| 7001 | "assist on %s: 0x%x\n", |
| 7002 | QETH_CARD_IFNAME(card), rc); |
| 7003 | } else { |
| 7004 | PRINT_INFO("VLAN enabled \n"); |
| 7005 | card->dev->features |= |
| 7006 | NETIF_F_HW_VLAN_FILTER | |
| 7007 | NETIF_F_HW_VLAN_TX | |
| 7008 | NETIF_F_HW_VLAN_RX; |
| 7009 | } |
| 7010 | #endif /* QETH_VLAN */ |
| 7011 | return rc; |
| 7012 | } |
| 7013 | |
| 7014 | static int |
| 7015 | qeth_start_ipa_multicast(struct qeth_card *card) |
| 7016 | { |
| 7017 | int rc; |
| 7018 | |
| 7019 | QETH_DBF_TEXT(trace,3,"stmcast"); |
| 7020 | |
| 7021 | if (!qeth_is_supported(card, IPA_MULTICASTING)) { |
| 7022 | PRINT_WARN("Multicast not supported on %s\n", |
| 7023 | QETH_CARD_IFNAME(card)); |
| 7024 | return -EOPNOTSUPP; |
| 7025 | } |
| 7026 | |
| 7027 | rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING, |
| 7028 | IPA_CMD_ASS_START,0); |
| 7029 | if (rc) { |
| 7030 | PRINT_WARN("Could not start multicast " |
| 7031 | "assist on %s: rc=%i\n", |
| 7032 | QETH_CARD_IFNAME(card), rc); |
| 7033 | } else { |
| 7034 | PRINT_INFO("Multicast enabled\n"); |
| 7035 | card->dev->flags |= IFF_MULTICAST; |
| 7036 | } |
| 7037 | return rc; |
| 7038 | } |
| 7039 | |
| 7040 | #ifdef CONFIG_QETH_IPV6 |
| 7041 | static int |
| 7042 | qeth_softsetup_ipv6(struct qeth_card *card) |
| 7043 | { |
| 7044 | int rc; |
| 7045 | |
| 7046 | QETH_DBF_TEXT(trace,3,"softipv6"); |
| 7047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7048 | rc = qeth_send_startlan(card, QETH_PROT_IPV6); |
| 7049 | if (rc) { |
| 7050 | PRINT_ERR("IPv6 startlan failed on %s\n", |
| 7051 | QETH_CARD_IFNAME(card)); |
| 7052 | return rc; |
| 7053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7054 | rc = qeth_query_ipassists(card,QETH_PROT_IPV6); |
| 7055 | if (rc) { |
| 7056 | PRINT_ERR("IPv6 query ipassist failed on %s\n", |
| 7057 | QETH_CARD_IFNAME(card)); |
| 7058 | return rc; |
| 7059 | } |
| 7060 | rc = qeth_send_simple_setassparms(card, IPA_IPV6, |
| 7061 | IPA_CMD_ASS_START, 3); |
| 7062 | if (rc) { |
| 7063 | PRINT_WARN("IPv6 start assist (version 4) failed " |
| 7064 | "on %s: 0x%x\n", |
| 7065 | QETH_CARD_IFNAME(card), rc); |
| 7066 | return rc; |
| 7067 | } |
| 7068 | rc = qeth_send_simple_setassparms_ipv6(card, IPA_IPV6, |
| 7069 | IPA_CMD_ASS_START); |
| 7070 | if (rc) { |
| 7071 | PRINT_WARN("IPV6 start assist (version 6) failed " |
| 7072 | "on %s: 0x%x\n", |
| 7073 | QETH_CARD_IFNAME(card), rc); |
| 7074 | return rc; |
| 7075 | } |
| 7076 | rc = qeth_send_simple_setassparms_ipv6(card, IPA_PASSTHRU, |
| 7077 | IPA_CMD_ASS_START); |
| 7078 | if (rc) { |
| 7079 | PRINT_WARN("Could not enable passthrough " |
| 7080 | "on %s: 0x%x\n", |
| 7081 | QETH_CARD_IFNAME(card), rc); |
| 7082 | return rc; |
| 7083 | } |
| 7084 | PRINT_INFO("IPV6 enabled \n"); |
| 7085 | return 0; |
| 7086 | } |
| 7087 | |
| 7088 | #endif |
| 7089 | |
| 7090 | static int |
| 7091 | qeth_start_ipa_ipv6(struct qeth_card *card) |
| 7092 | { |
| 7093 | int rc = 0; |
| 7094 | #ifdef CONFIG_QETH_IPV6 |
| 7095 | QETH_DBF_TEXT(trace,3,"strtipv6"); |
| 7096 | |
| 7097 | if (!qeth_is_supported(card, IPA_IPV6)) { |
| 7098 | PRINT_WARN("IPv6 not supported on %s\n", |
| 7099 | QETH_CARD_IFNAME(card)); |
| 7100 | return 0; |
| 7101 | } |
| 7102 | rc = qeth_softsetup_ipv6(card); |
| 7103 | #endif |
| 7104 | return rc ; |
| 7105 | } |
| 7106 | |
| 7107 | static int |
| 7108 | qeth_start_ipa_broadcast(struct qeth_card *card) |
| 7109 | { |
| 7110 | int rc; |
| 7111 | |
| 7112 | QETH_DBF_TEXT(trace,3,"stbrdcst"); |
| 7113 | card->info.broadcast_capable = 0; |
| 7114 | if (!qeth_is_supported(card, IPA_FILTERING)) { |
| 7115 | PRINT_WARN("Broadcast not supported on %s\n", |
| 7116 | QETH_CARD_IFNAME(card)); |
| 7117 | rc = -EOPNOTSUPP; |
| 7118 | goto out; |
| 7119 | } |
| 7120 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7121 | IPA_CMD_ASS_START, 0); |
| 7122 | if (rc) { |
| 7123 | PRINT_WARN("Could not enable broadcasting filtering " |
| 7124 | "on %s: 0x%x\n", |
| 7125 | QETH_CARD_IFNAME(card), rc); |
| 7126 | goto out; |
| 7127 | } |
| 7128 | |
| 7129 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7130 | IPA_CMD_ASS_CONFIGURE, 1); |
| 7131 | if (rc) { |
| 7132 | PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n", |
| 7133 | QETH_CARD_IFNAME(card), rc); |
| 7134 | goto out; |
| 7135 | } |
| 7136 | card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; |
| 7137 | PRINT_INFO("Broadcast enabled \n"); |
| 7138 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
| 7139 | IPA_CMD_ASS_ENABLE, 1); |
| 7140 | if (rc) { |
| 7141 | PRINT_WARN("Could not set up broadcast echo filtering on " |
| 7142 | "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc); |
| 7143 | goto out; |
| 7144 | } |
| 7145 | card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; |
| 7146 | out: |
| 7147 | if (card->info.broadcast_capable) |
| 7148 | card->dev->flags |= IFF_BROADCAST; |
| 7149 | else |
| 7150 | card->dev->flags &= ~IFF_BROADCAST; |
| 7151 | return rc; |
| 7152 | } |
| 7153 | |
| 7154 | static int |
| 7155 | qeth_send_checksum_command(struct qeth_card *card) |
| 7156 | { |
| 7157 | int rc; |
| 7158 | |
| 7159 | rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 7160 | IPA_CMD_ASS_START, 0); |
| 7161 | if (rc) { |
| 7162 | PRINT_WARN("Starting Inbound HW Checksumming failed on %s: " |
| 7163 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 7164 | QETH_CARD_IFNAME(card), rc); |
| 7165 | return rc; |
| 7166 | } |
| 7167 | rc = qeth_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 7168 | IPA_CMD_ASS_ENABLE, |
| 7169 | card->info.csum_mask); |
| 7170 | if (rc) { |
| 7171 | PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: " |
| 7172 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 7173 | QETH_CARD_IFNAME(card), rc); |
| 7174 | return rc; |
| 7175 | } |
| 7176 | return 0; |
| 7177 | } |
| 7178 | |
| 7179 | static int |
| 7180 | qeth_start_ipa_checksum(struct qeth_card *card) |
| 7181 | { |
| 7182 | int rc = 0; |
| 7183 | |
| 7184 | QETH_DBF_TEXT(trace,3,"strtcsum"); |
| 7185 | |
| 7186 | if (card->options.checksum_type == NO_CHECKSUMMING) { |
| 7187 | PRINT_WARN("Using no checksumming on %s.\n", |
| 7188 | QETH_CARD_IFNAME(card)); |
| 7189 | return 0; |
| 7190 | } |
| 7191 | if (card->options.checksum_type == SW_CHECKSUMMING) { |
| 7192 | PRINT_WARN("Using SW checksumming on %s.\n", |
| 7193 | QETH_CARD_IFNAME(card)); |
| 7194 | return 0; |
| 7195 | } |
| 7196 | if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
| 7197 | PRINT_WARN("Inbound HW Checksumming not " |
| 7198 | "supported on %s,\ncontinuing " |
| 7199 | "using Inbound SW Checksumming\n", |
| 7200 | QETH_CARD_IFNAME(card)); |
| 7201 | card->options.checksum_type = SW_CHECKSUMMING; |
| 7202 | return 0; |
| 7203 | } |
| 7204 | rc = qeth_send_checksum_command(card); |
| 7205 | if (!rc) { |
| 7206 | PRINT_INFO("HW Checksumming (inbound) enabled \n"); |
| 7207 | } |
| 7208 | return rc; |
| 7209 | } |
| 7210 | |
| 7211 | static int |
| 7212 | qeth_start_ipa_tso(struct qeth_card *card) |
| 7213 | { |
| 7214 | int rc; |
| 7215 | |
| 7216 | QETH_DBF_TEXT(trace,3,"sttso"); |
| 7217 | |
| 7218 | if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) { |
| 7219 | PRINT_WARN("Outbound TSO not supported on %s\n", |
| 7220 | QETH_CARD_IFNAME(card)); |
| 7221 | rc = -EOPNOTSUPP; |
| 7222 | } else { |
| 7223 | rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO, |
| 7224 | IPA_CMD_ASS_START,0); |
| 7225 | if (rc) |
| 7226 | PRINT_WARN("Could not start outbound TSO " |
| 7227 | "assist on %s: rc=%i\n", |
| 7228 | QETH_CARD_IFNAME(card), rc); |
| 7229 | else |
| 7230 | PRINT_INFO("Outbound TSO enabled\n"); |
| 7231 | } |
| 7232 | if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)){ |
| 7233 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 7234 | card->dev->features &= ~ (NETIF_F_TSO | NETIF_F_SG); |
| 7235 | } |
| 7236 | return rc; |
| 7237 | } |
| 7238 | |
| 7239 | static int |
| 7240 | qeth_start_ipassists(struct qeth_card *card) |
| 7241 | { |
| 7242 | QETH_DBF_TEXT(trace,3,"strtipas"); |
| 7243 | qeth_start_ipa_arp_processing(card); /* go on*/ |
| 7244 | qeth_start_ipa_ip_fragmentation(card); /* go on*/ |
| 7245 | qeth_start_ipa_source_mac(card); /* go on*/ |
| 7246 | qeth_start_ipa_vlan(card); /* go on*/ |
| 7247 | qeth_start_ipa_multicast(card); /* go on*/ |
| 7248 | qeth_start_ipa_ipv6(card); /* go on*/ |
| 7249 | qeth_start_ipa_broadcast(card); /* go on*/ |
| 7250 | qeth_start_ipa_checksum(card); /* go on*/ |
| 7251 | qeth_start_ipa_tso(card); /* go on*/ |
| 7252 | return 0; |
| 7253 | } |
| 7254 | |
| 7255 | static int |
| 7256 | qeth_send_setrouting(struct qeth_card *card, enum qeth_routing_types type, |
| 7257 | enum qeth_prot_versions prot) |
| 7258 | { |
| 7259 | int rc; |
| 7260 | struct qeth_ipa_cmd *cmd; |
| 7261 | struct qeth_cmd_buffer *iob; |
| 7262 | |
| 7263 | QETH_DBF_TEXT(trace,4,"setroutg"); |
| 7264 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot); |
| 7265 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7266 | cmd->data.setrtg.type = (type); |
| 7267 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 7268 | |
| 7269 | return rc; |
| 7270 | |
| 7271 | } |
| 7272 | |
| 7273 | static void |
| 7274 | qeth_correct_routing_type(struct qeth_card *card, enum qeth_routing_types *type, |
| 7275 | enum qeth_prot_versions prot) |
| 7276 | { |
| 7277 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 7278 | switch (*type) { |
| 7279 | case NO_ROUTER: |
| 7280 | case PRIMARY_CONNECTOR: |
| 7281 | case SECONDARY_CONNECTOR: |
| 7282 | case MULTICAST_ROUTER: |
| 7283 | return; |
| 7284 | default: |
| 7285 | goto out_inval; |
| 7286 | } |
| 7287 | } else { |
| 7288 | switch (*type) { |
| 7289 | case NO_ROUTER: |
| 7290 | case PRIMARY_ROUTER: |
| 7291 | case SECONDARY_ROUTER: |
| 7292 | return; |
| 7293 | case MULTICAST_ROUTER: |
| 7294 | if (qeth_is_ipafunc_supported(card, prot, |
| 7295 | IPA_OSA_MC_ROUTER)) |
| 7296 | return; |
| 7297 | default: |
| 7298 | goto out_inval; |
| 7299 | } |
| 7300 | } |
| 7301 | out_inval: |
| 7302 | PRINT_WARN("Routing type '%s' not supported for interface %s.\n" |
| 7303 | "Router status set to 'no router'.\n", |
| 7304 | ((*type == PRIMARY_ROUTER)? "primary router" : |
| 7305 | (*type == SECONDARY_ROUTER)? "secondary router" : |
| 7306 | (*type == PRIMARY_CONNECTOR)? "primary connector" : |
| 7307 | (*type == SECONDARY_CONNECTOR)? "secondary connector" : |
| 7308 | (*type == MULTICAST_ROUTER)? "multicast router" : |
| 7309 | "unknown"), |
| 7310 | card->dev->name); |
| 7311 | *type = NO_ROUTER; |
| 7312 | } |
| 7313 | |
| 7314 | int |
| 7315 | qeth_setrouting_v4(struct qeth_card *card) |
| 7316 | { |
| 7317 | int rc; |
| 7318 | |
| 7319 | QETH_DBF_TEXT(trace,3,"setrtg4"); |
| 7320 | |
| 7321 | qeth_correct_routing_type(card, &card->options.route4.type, |
| 7322 | QETH_PROT_IPV4); |
| 7323 | |
| 7324 | rc = qeth_send_setrouting(card, card->options.route4.type, |
| 7325 | QETH_PROT_IPV4); |
| 7326 | if (rc) { |
| 7327 | card->options.route4.type = NO_ROUTER; |
| 7328 | PRINT_WARN("Error (0x%04x) while setting routing type on %s. " |
| 7329 | "Type set to 'no router'.\n", |
| 7330 | rc, QETH_CARD_IFNAME(card)); |
| 7331 | } |
| 7332 | return rc; |
| 7333 | } |
| 7334 | |
| 7335 | int |
| 7336 | qeth_setrouting_v6(struct qeth_card *card) |
| 7337 | { |
| 7338 | int rc = 0; |
| 7339 | |
| 7340 | QETH_DBF_TEXT(trace,3,"setrtg6"); |
| 7341 | #ifdef CONFIG_QETH_IPV6 |
| 7342 | |
| 7343 | qeth_correct_routing_type(card, &card->options.route6.type, |
| 7344 | QETH_PROT_IPV6); |
| 7345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7346 | rc = qeth_send_setrouting(card, card->options.route6.type, |
| 7347 | QETH_PROT_IPV6); |
| 7348 | if (rc) { |
| 7349 | card->options.route6.type = NO_ROUTER; |
| 7350 | PRINT_WARN("Error (0x%04x) while setting routing type on %s. " |
| 7351 | "Type set to 'no router'.\n", |
| 7352 | rc, QETH_CARD_IFNAME(card)); |
| 7353 | } |
| 7354 | #endif |
| 7355 | return rc; |
| 7356 | } |
| 7357 | |
| 7358 | int |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7359 | 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] | 7360 | { |
| 7361 | int rc = 0; |
| 7362 | |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7363 | if (card->dev == NULL) { |
| 7364 | card->options.large_send = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7365 | return 0; |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7366 | } |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7367 | if (card->state == CARD_STATE_UP) |
| 7368 | netif_tx_disable(card->dev); |
Frank Pavlic | 9cb90de | 2005-09-14 18:03:26 +0200 | [diff] [blame] | 7369 | card->options.large_send = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7370 | switch (card->options.large_send) { |
| 7371 | case QETH_LARGE_SEND_EDDP: |
| 7372 | card->dev->features |= NETIF_F_TSO | NETIF_F_SG; |
| 7373 | break; |
| 7374 | case QETH_LARGE_SEND_TSO: |
| 7375 | if (qeth_is_supported(card, IPA_OUTBOUND_TSO)){ |
| 7376 | card->dev->features |= NETIF_F_TSO | NETIF_F_SG; |
| 7377 | } else { |
| 7378 | PRINT_WARN("TSO not supported on %s. " |
| 7379 | "large_send set to 'no'.\n", |
| 7380 | card->dev->name); |
| 7381 | card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG); |
| 7382 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 7383 | rc = -EOPNOTSUPP; |
| 7384 | } |
| 7385 | break; |
| 7386 | default: /* includes QETH_LARGE_SEND_NO */ |
| 7387 | card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG); |
| 7388 | break; |
| 7389 | } |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7390 | if (card->state == CARD_STATE_UP) |
| 7391 | netif_wake_queue(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7392 | return rc; |
| 7393 | } |
| 7394 | |
| 7395 | /* |
| 7396 | * softsetup card: init IPA stuff |
| 7397 | */ |
| 7398 | static int |
| 7399 | qeth_softsetup_card(struct qeth_card *card) |
| 7400 | { |
| 7401 | int rc; |
| 7402 | |
| 7403 | QETH_DBF_TEXT(setup, 2, "softsetp"); |
| 7404 | |
| 7405 | if ((rc = qeth_send_startlan(card, QETH_PROT_IPV4))){ |
| 7406 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7407 | if (rc == 0xe080){ |
| 7408 | PRINT_WARN("LAN on card %s if offline! " |
| 7409 | "Continuing softsetup.\n", |
| 7410 | CARD_BUS_ID(card)); |
| 7411 | card->lan_online = 0; |
| 7412 | } else |
| 7413 | return rc; |
| 7414 | } else |
| 7415 | card->lan_online = 1; |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7416 | if (card->info.type==QETH_CARD_TYPE_OSN) |
| 7417 | goto out; |
Frank Pavlic | 66cc5d5 | 2006-02-07 17:04:38 +0100 | [diff] [blame] | 7418 | qeth_set_large_send(card, card->options.large_send); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7419 | if (card->options.layer2) { |
| 7420 | card->dev->features |= |
| 7421 | NETIF_F_HW_VLAN_FILTER | |
| 7422 | NETIF_F_HW_VLAN_TX | |
| 7423 | NETIF_F_HW_VLAN_RX; |
| 7424 | card->dev->flags|=IFF_MULTICAST|IFF_BROADCAST; |
| 7425 | card->info.broadcast_capable=1; |
| 7426 | if ((rc = qeth_layer2_initialize(card))) { |
| 7427 | QETH_DBF_TEXT_(setup, 2, "L2err%d", rc); |
| 7428 | return rc; |
| 7429 | } |
| 7430 | #ifdef CONFIG_QETH_VLAN |
| 7431 | qeth_layer2_process_vlans(card, 0); |
| 7432 | #endif |
| 7433 | goto out; |
| 7434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7435 | if ((rc = qeth_setadapter_parms(card))) |
| 7436 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7437 | if ((rc = qeth_start_ipassists(card))) |
| 7438 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 7439 | if ((rc = qeth_setrouting_v4(card))) |
| 7440 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 7441 | if ((rc = qeth_setrouting_v6(card))) |
| 7442 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 7443 | out: |
Ursula Braun | b85e1fa | 2006-05-24 09:51:11 +0200 | [diff] [blame] | 7444 | netif_tx_disable(card->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7445 | return 0; |
| 7446 | } |
| 7447 | |
| 7448 | #ifdef CONFIG_QETH_IPV6 |
| 7449 | static int |
| 7450 | qeth_get_unique_id_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 7451 | unsigned long data) |
| 7452 | { |
| 7453 | struct qeth_ipa_cmd *cmd; |
| 7454 | |
| 7455 | cmd = (struct qeth_ipa_cmd *) data; |
| 7456 | if (cmd->hdr.return_code == 0) |
| 7457 | card->info.unique_id = *((__u16 *) |
| 7458 | &cmd->data.create_destroy_addr.unique_id[6]); |
| 7459 | else { |
| 7460 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7461 | UNIQUE_ID_NOT_BY_CARD; |
| 7462 | PRINT_WARN("couldn't get a unique id from the card on device " |
| 7463 | "%s (result=x%x), using default id. ipv6 " |
| 7464 | "autoconfig on other lpars may lead to duplicate " |
| 7465 | "ip addresses. please use manually " |
| 7466 | "configured ones.\n", |
| 7467 | CARD_BUS_ID(card), cmd->hdr.return_code); |
| 7468 | } |
| 7469 | return 0; |
| 7470 | } |
| 7471 | #endif |
| 7472 | |
| 7473 | static int |
| 7474 | qeth_put_unique_id(struct qeth_card *card) |
| 7475 | { |
| 7476 | |
| 7477 | int rc = 0; |
| 7478 | #ifdef CONFIG_QETH_IPV6 |
| 7479 | struct qeth_cmd_buffer *iob; |
| 7480 | struct qeth_ipa_cmd *cmd; |
| 7481 | |
| 7482 | QETH_DBF_TEXT(trace,2,"puniqeid"); |
| 7483 | |
| 7484 | if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) == |
| 7485 | UNIQUE_ID_NOT_BY_CARD) |
| 7486 | return -1; |
| 7487 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR, |
| 7488 | QETH_PROT_IPV6); |
| 7489 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7490 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 7491 | card->info.unique_id; |
| 7492 | memcpy(&cmd->data.create_destroy_addr.unique_id[0], |
| 7493 | card->dev->dev_addr, OSA_ADDR_LEN); |
| 7494 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 7495 | #else |
| 7496 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7497 | UNIQUE_ID_NOT_BY_CARD; |
| 7498 | #endif |
| 7499 | return rc; |
| 7500 | } |
| 7501 | |
| 7502 | /** |
| 7503 | * Clear IP List |
| 7504 | */ |
| 7505 | static void |
| 7506 | qeth_clear_ip_list(struct qeth_card *card, int clean, int recover) |
| 7507 | { |
| 7508 | struct qeth_ipaddr *addr, *tmp; |
| 7509 | unsigned long flags; |
| 7510 | |
| 7511 | QETH_DBF_TEXT(trace,4,"clearip"); |
| 7512 | spin_lock_irqsave(&card->ip_lock, flags); |
| 7513 | /* clear todo list */ |
| 7514 | list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry){ |
| 7515 | list_del(&addr->entry); |
| 7516 | kfree(addr); |
| 7517 | } |
| 7518 | |
| 7519 | while (!list_empty(&card->ip_list)) { |
| 7520 | addr = list_entry(card->ip_list.next, |
| 7521 | struct qeth_ipaddr, entry); |
| 7522 | list_del_init(&addr->entry); |
| 7523 | if (clean) { |
| 7524 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 7525 | qeth_deregister_addr_entry(card, addr); |
| 7526 | spin_lock_irqsave(&card->ip_lock, flags); |
| 7527 | } |
| 7528 | if (!recover || addr->is_multicast) { |
| 7529 | kfree(addr); |
| 7530 | continue; |
| 7531 | } |
| 7532 | list_add_tail(&addr->entry, card->ip_tbd_list); |
| 7533 | } |
| 7534 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 7535 | } |
| 7536 | |
| 7537 | static void |
| 7538 | qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads, |
| 7539 | int clear_start_mask) |
| 7540 | { |
| 7541 | unsigned long flags; |
| 7542 | |
| 7543 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 7544 | card->thread_allowed_mask = threads; |
| 7545 | if (clear_start_mask) |
| 7546 | card->thread_start_mask &= threads; |
| 7547 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 7548 | wake_up(&card->wait_q); |
| 7549 | } |
| 7550 | |
| 7551 | static inline int |
| 7552 | qeth_threads_running(struct qeth_card *card, unsigned long threads) |
| 7553 | { |
| 7554 | unsigned long flags; |
| 7555 | int rc = 0; |
| 7556 | |
| 7557 | spin_lock_irqsave(&card->thread_mask_lock, flags); |
| 7558 | rc = (card->thread_running_mask & threads); |
| 7559 | spin_unlock_irqrestore(&card->thread_mask_lock, flags); |
| 7560 | return rc; |
| 7561 | } |
| 7562 | |
| 7563 | static int |
| 7564 | qeth_wait_for_threads(struct qeth_card *card, unsigned long threads) |
| 7565 | { |
| 7566 | return wait_event_interruptible(card->wait_q, |
| 7567 | qeth_threads_running(card, threads) == 0); |
| 7568 | } |
| 7569 | |
| 7570 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7571 | qeth_stop_card(struct qeth_card *card, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7572 | { |
| 7573 | int rc = 0; |
| 7574 | |
| 7575 | QETH_DBF_TEXT(setup ,2,"stopcard"); |
| 7576 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 7577 | |
| 7578 | qeth_set_allowed_threads(card, 0, 1); |
| 7579 | if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) |
| 7580 | return -ERESTARTSYS; |
| 7581 | if (card->read.state == CH_STATE_UP && |
| 7582 | card->write.state == CH_STATE_UP && |
| 7583 | (card->state == CARD_STATE_UP)) { |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7584 | if (recovery_mode && |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7585 | card->info.type != QETH_CARD_TYPE_OSN) { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7586 | qeth_stop(card->dev); |
| 7587 | } else { |
| 7588 | rtnl_lock(); |
| 7589 | dev_close(card->dev); |
| 7590 | rtnl_unlock(); |
| 7591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7592 | if (!card->use_hard_stop) { |
| 7593 | __u8 *mac = &card->dev->dev_addr[0]; |
| 7594 | rc = qeth_layer2_send_delmac(card, mac); |
| 7595 | QETH_DBF_TEXT_(setup, 2, "Lerr%d", rc); |
| 7596 | if ((rc = qeth_send_stoplan(card))) |
| 7597 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7598 | } |
| 7599 | card->state = CARD_STATE_SOFTSETUP; |
| 7600 | } |
| 7601 | if (card->state == CARD_STATE_SOFTSETUP) { |
| 7602 | #ifdef CONFIG_QETH_VLAN |
| 7603 | if (card->options.layer2) |
| 7604 | qeth_layer2_process_vlans(card, 1); |
| 7605 | #endif |
| 7606 | qeth_clear_ip_list(card, !card->use_hard_stop, 1); |
| 7607 | qeth_clear_ipacmd_list(card); |
| 7608 | card->state = CARD_STATE_HARDSETUP; |
| 7609 | } |
| 7610 | if (card->state == CARD_STATE_HARDSETUP) { |
| 7611 | if ((!card->use_hard_stop) && |
| 7612 | (!card->options.layer2)) |
| 7613 | if ((rc = qeth_put_unique_id(card))) |
| 7614 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7615 | qeth_qdio_clear_card(card, 0); |
| 7616 | qeth_clear_qdio_buffers(card); |
| 7617 | qeth_clear_working_pool_list(card); |
| 7618 | card->state = CARD_STATE_DOWN; |
| 7619 | } |
| 7620 | if (card->state == CARD_STATE_DOWN) { |
| 7621 | qeth_clear_cmd_buffers(&card->read); |
| 7622 | qeth_clear_cmd_buffers(&card->write); |
| 7623 | } |
| 7624 | card->use_hard_stop = 0; |
| 7625 | return rc; |
| 7626 | } |
| 7627 | |
| 7628 | |
| 7629 | static int |
| 7630 | qeth_get_unique_id(struct qeth_card *card) |
| 7631 | { |
| 7632 | int rc = 0; |
| 7633 | #ifdef CONFIG_QETH_IPV6 |
| 7634 | struct qeth_cmd_buffer *iob; |
| 7635 | struct qeth_ipa_cmd *cmd; |
| 7636 | |
| 7637 | QETH_DBF_TEXT(setup, 2, "guniqeid"); |
| 7638 | |
| 7639 | if (!qeth_is_supported(card,IPA_IPV6)) { |
| 7640 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7641 | UNIQUE_ID_NOT_BY_CARD; |
| 7642 | return 0; |
| 7643 | } |
| 7644 | |
| 7645 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 7646 | QETH_PROT_IPV6); |
| 7647 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 7648 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 7649 | card->info.unique_id; |
| 7650 | |
| 7651 | rc = qeth_send_ipa_cmd(card, iob, qeth_get_unique_id_cb, NULL); |
| 7652 | #else |
| 7653 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 7654 | UNIQUE_ID_NOT_BY_CARD; |
| 7655 | #endif |
| 7656 | return rc; |
| 7657 | } |
| 7658 | static void |
| 7659 | qeth_print_status_with_portname(struct qeth_card *card) |
| 7660 | { |
| 7661 | char dbf_text[15]; |
| 7662 | int i; |
| 7663 | |
| 7664 | sprintf(dbf_text, "%s", card->info.portname + 1); |
| 7665 | for (i = 0; i < 8; i++) |
| 7666 | dbf_text[i] = |
| 7667 | (char) _ebcasc[(__u8) dbf_text[i]]; |
| 7668 | dbf_text[8] = 0; |
| 7669 | printk("qeth: Device %s/%s/%s is a%s card%s%s%s\n" |
| 7670 | "with link type %s (portname: %s)\n", |
| 7671 | CARD_RDEV_ID(card), |
| 7672 | CARD_WDEV_ID(card), |
| 7673 | CARD_DDEV_ID(card), |
| 7674 | qeth_get_cardname(card), |
| 7675 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7676 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7677 | (card->info.mcl_level[0]) ? ")" : "", |
| 7678 | qeth_get_cardname_short(card), |
| 7679 | dbf_text); |
| 7680 | |
| 7681 | } |
| 7682 | |
| 7683 | static void |
| 7684 | qeth_print_status_no_portname(struct qeth_card *card) |
| 7685 | { |
| 7686 | if (card->info.portname[0]) |
| 7687 | printk("qeth: Device %s/%s/%s is a%s " |
| 7688 | "card%s%s%s\nwith link type %s " |
| 7689 | "(no portname needed by interface).\n", |
| 7690 | CARD_RDEV_ID(card), |
| 7691 | CARD_WDEV_ID(card), |
| 7692 | CARD_DDEV_ID(card), |
| 7693 | qeth_get_cardname(card), |
| 7694 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7695 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7696 | (card->info.mcl_level[0]) ? ")" : "", |
| 7697 | qeth_get_cardname_short(card)); |
| 7698 | else |
| 7699 | printk("qeth: Device %s/%s/%s is a%s " |
| 7700 | "card%s%s%s\nwith link type %s.\n", |
| 7701 | CARD_RDEV_ID(card), |
| 7702 | CARD_WDEV_ID(card), |
| 7703 | CARD_DDEV_ID(card), |
| 7704 | qeth_get_cardname(card), |
| 7705 | (card->info.mcl_level[0]) ? " (level: " : "", |
| 7706 | (card->info.mcl_level[0]) ? card->info.mcl_level : "", |
| 7707 | (card->info.mcl_level[0]) ? ")" : "", |
| 7708 | qeth_get_cardname_short(card)); |
| 7709 | } |
| 7710 | |
| 7711 | static void |
| 7712 | qeth_print_status_message(struct qeth_card *card) |
| 7713 | { |
| 7714 | switch (card->info.type) { |
| 7715 | case QETH_CARD_TYPE_OSAE: |
| 7716 | /* VM will use a non-zero first character |
| 7717 | * to indicate a HiperSockets like reporting |
| 7718 | * of the level OSA sets the first character to zero |
| 7719 | * */ |
| 7720 | if (!card->info.mcl_level[0]) { |
| 7721 | sprintf(card->info.mcl_level,"%02x%02x", |
| 7722 | card->info.mcl_level[2], |
| 7723 | card->info.mcl_level[3]); |
| 7724 | |
| 7725 | card->info.mcl_level[QETH_MCL_LENGTH] = 0; |
| 7726 | break; |
| 7727 | } |
| 7728 | /* fallthrough */ |
| 7729 | case QETH_CARD_TYPE_IQD: |
| 7730 | card->info.mcl_level[0] = (char) _ebcasc[(__u8) |
| 7731 | card->info.mcl_level[0]]; |
| 7732 | card->info.mcl_level[1] = (char) _ebcasc[(__u8) |
| 7733 | card->info.mcl_level[1]]; |
| 7734 | card->info.mcl_level[2] = (char) _ebcasc[(__u8) |
| 7735 | card->info.mcl_level[2]]; |
| 7736 | card->info.mcl_level[3] = (char) _ebcasc[(__u8) |
| 7737 | card->info.mcl_level[3]]; |
| 7738 | card->info.mcl_level[QETH_MCL_LENGTH] = 0; |
| 7739 | break; |
| 7740 | default: |
| 7741 | memset(&card->info.mcl_level[0], 0, QETH_MCL_LENGTH + 1); |
| 7742 | } |
| 7743 | if (card->info.portname_required) |
| 7744 | qeth_print_status_with_portname(card); |
| 7745 | else |
| 7746 | qeth_print_status_no_portname(card); |
| 7747 | } |
| 7748 | |
| 7749 | static int |
| 7750 | qeth_register_netdev(struct qeth_card *card) |
| 7751 | { |
| 7752 | QETH_DBF_TEXT(setup, 3, "regnetd"); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7753 | if (card->dev->reg_state != NETREG_UNINITIALIZED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7754 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7755 | /* sysfs magic */ |
| 7756 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
| 7757 | return register_netdev(card->dev); |
| 7758 | } |
| 7759 | |
| 7760 | static void |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7761 | qeth_start_again(struct qeth_card *card, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7762 | { |
| 7763 | QETH_DBF_TEXT(setup ,2, "startag"); |
| 7764 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 7765 | if (recovery_mode && |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7766 | card->info.type != QETH_CARD_TYPE_OSN) { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7767 | qeth_open(card->dev); |
| 7768 | } else { |
| 7769 | rtnl_lock(); |
| 7770 | dev_open(card->dev); |
| 7771 | rtnl_unlock(); |
| 7772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7773 | /* this also sets saved unicast addresses */ |
| 7774 | qeth_set_multicast_list(card->dev); |
| 7775 | } |
| 7776 | |
| 7777 | |
| 7778 | /* Layer 2 specific stuff */ |
| 7779 | #define IGNORE_PARAM_EQ(option,value,reset_value,msg) \ |
| 7780 | if (card->options.option == value) { \ |
| 7781 | PRINT_ERR("%s not supported with layer 2 " \ |
| 7782 | "functionality, ignoring option on read" \ |
| 7783 | "channel device %s .\n",msg,CARD_RDEV_ID(card)); \ |
| 7784 | card->options.option = reset_value; \ |
| 7785 | } |
| 7786 | #define IGNORE_PARAM_NEQ(option,value,reset_value,msg) \ |
| 7787 | if (card->options.option != value) { \ |
| 7788 | PRINT_ERR("%s not supported with layer 2 " \ |
| 7789 | "functionality, ignoring option on read" \ |
| 7790 | "channel device %s .\n",msg,CARD_RDEV_ID(card)); \ |
| 7791 | card->options.option = reset_value; \ |
| 7792 | } |
| 7793 | |
| 7794 | |
| 7795 | static void qeth_make_parameters_consistent(struct qeth_card *card) |
| 7796 | { |
| 7797 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7798 | if (card->options.layer2 == 0) |
| 7799 | return; |
| 7800 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 7801 | return; |
| 7802 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 7803 | PRINT_ERR("Device %s does not support layer 2 functionality." \ |
| 7804 | " Ignoring layer2 option.\n",CARD_BUS_ID(card)); |
| 7805 | card->options.layer2 = 0; |
| 7806 | return; |
| 7807 | } |
| 7808 | IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER, |
| 7809 | "Routing options are"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7810 | #ifdef CONFIG_QETH_IPV6 |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7811 | IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER, |
| 7812 | "Routing options are"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7813 | #endif |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7814 | IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING, |
| 7815 | QETH_CHECKSUM_DEFAULT, |
| 7816 | "Checksumming options are"); |
| 7817 | IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS, |
| 7818 | QETH_TR_BROADCAST_ALLRINGS, |
| 7819 | "Broadcast mode options are"); |
| 7820 | IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL, |
| 7821 | QETH_TR_MACADDR_NONCANONICAL, |
| 7822 | "Canonical MAC addr options are"); |
| 7823 | IGNORE_PARAM_NEQ(fake_broadcast, 0, 0, |
| 7824 | "Broadcast faking options are"); |
| 7825 | IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN, |
| 7826 | DEFAULT_ADD_HHLEN,"Option add_hhlen is"); |
| 7827 | IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7828 | } |
| 7829 | |
| 7830 | |
| 7831 | static int |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7832 | __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7833 | { |
| 7834 | struct qeth_card *card = gdev->dev.driver_data; |
| 7835 | int rc = 0; |
| 7836 | enum qeth_card_states recover_flag; |
| 7837 | |
| 7838 | BUG_ON(!card); |
| 7839 | QETH_DBF_TEXT(setup ,2, "setonlin"); |
| 7840 | QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); |
| 7841 | |
| 7842 | qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1); |
| 7843 | if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)){ |
| 7844 | PRINT_WARN("set_online of card %s interrupted by user!\n", |
| 7845 | CARD_BUS_ID(card)); |
| 7846 | return -ERESTARTSYS; |
| 7847 | } |
| 7848 | |
| 7849 | recover_flag = card->state; |
| 7850 | if ((rc = ccw_device_set_online(CARD_RDEV(card))) || |
| 7851 | (rc = ccw_device_set_online(CARD_WDEV(card))) || |
| 7852 | (rc = ccw_device_set_online(CARD_DDEV(card)))){ |
| 7853 | QETH_DBF_TEXT_(setup, 2, "1err%d", rc); |
| 7854 | return -EIO; |
| 7855 | } |
| 7856 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 7857 | qeth_make_parameters_consistent(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7858 | |
| 7859 | if ((rc = qeth_hardsetup_card(card))){ |
| 7860 | QETH_DBF_TEXT_(setup, 2, "2err%d", rc); |
| 7861 | goto out_remove; |
| 7862 | } |
| 7863 | card->state = CARD_STATE_HARDSETUP; |
| 7864 | |
| 7865 | if (!(rc = qeth_query_ipassists(card,QETH_PROT_IPV4))) |
| 7866 | rc = qeth_get_unique_id(card); |
| 7867 | |
| 7868 | if (rc && card->options.layer2 == 0) { |
| 7869 | QETH_DBF_TEXT_(setup, 2, "3err%d", rc); |
| 7870 | goto out_remove; |
| 7871 | } |
| 7872 | qeth_print_status_message(card); |
| 7873 | if ((rc = qeth_register_netdev(card))){ |
| 7874 | QETH_DBF_TEXT_(setup, 2, "4err%d", rc); |
| 7875 | goto out_remove; |
| 7876 | } |
| 7877 | if ((rc = qeth_softsetup_card(card))){ |
| 7878 | QETH_DBF_TEXT_(setup, 2, "5err%d", rc); |
| 7879 | goto out_remove; |
| 7880 | } |
| 7881 | card->state = CARD_STATE_SOFTSETUP; |
| 7882 | |
| 7883 | if ((rc = qeth_init_qdio_queues(card))){ |
| 7884 | QETH_DBF_TEXT_(setup, 2, "6err%d", rc); |
| 7885 | goto out_remove; |
| 7886 | } |
Frank Pavlic | 4965e97 | 2005-12-13 08:22:30 +0100 | [diff] [blame] | 7887 | netif_carrier_on(card->dev); |
| 7888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7889 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 7890 | if (recover_flag == CARD_STATE_RECOVER) |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7891 | qeth_start_again(card, recovery_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7892 | qeth_notify_processes(); |
| 7893 | return 0; |
| 7894 | out_remove: |
| 7895 | card->use_hard_stop = 1; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7896 | qeth_stop_card(card, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7897 | ccw_device_set_offline(CARD_DDEV(card)); |
| 7898 | ccw_device_set_offline(CARD_WDEV(card)); |
| 7899 | ccw_device_set_offline(CARD_RDEV(card)); |
| 7900 | if (recover_flag == CARD_STATE_RECOVER) |
| 7901 | card->state = CARD_STATE_RECOVER; |
| 7902 | else |
| 7903 | card->state = CARD_STATE_DOWN; |
| 7904 | return -ENODEV; |
| 7905 | } |
| 7906 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 7907 | static int |
| 7908 | qeth_set_online(struct ccwgroup_device *gdev) |
| 7909 | { |
| 7910 | return __qeth_set_online(gdev, 0); |
| 7911 | } |
| 7912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7913 | static struct ccw_device_id qeth_ids[] = { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 7914 | {CCW_DEVICE(0x1731, 0x01), .driver_info = QETH_CARD_TYPE_OSAE}, |
| 7915 | {CCW_DEVICE(0x1731, 0x05), .driver_info = QETH_CARD_TYPE_IQD}, |
| 7916 | {CCW_DEVICE(0x1731, 0x06), .driver_info = QETH_CARD_TYPE_OSN}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7917 | {}, |
| 7918 | }; |
| 7919 | MODULE_DEVICE_TABLE(ccw, qeth_ids); |
| 7920 | |
| 7921 | struct device *qeth_root_dev = NULL; |
| 7922 | |
| 7923 | struct ccwgroup_driver qeth_ccwgroup_driver = { |
| 7924 | .owner = THIS_MODULE, |
| 7925 | .name = "qeth", |
| 7926 | .driver_id = 0xD8C5E3C8, |
| 7927 | .probe = qeth_probe_device, |
| 7928 | .remove = qeth_remove_device, |
| 7929 | .set_online = qeth_set_online, |
| 7930 | .set_offline = qeth_set_offline, |
| 7931 | }; |
| 7932 | |
| 7933 | struct ccw_driver qeth_ccw_driver = { |
| 7934 | .name = "qeth", |
| 7935 | .ids = qeth_ids, |
| 7936 | .probe = ccwgroup_probe_ccwdev, |
| 7937 | .remove = ccwgroup_remove_ccwdev, |
| 7938 | }; |
| 7939 | |
| 7940 | |
| 7941 | static void |
| 7942 | qeth_unregister_dbf_views(void) |
| 7943 | { |
| 7944 | if (qeth_dbf_setup) |
| 7945 | debug_unregister(qeth_dbf_setup); |
| 7946 | if (qeth_dbf_qerr) |
| 7947 | debug_unregister(qeth_dbf_qerr); |
| 7948 | if (qeth_dbf_sense) |
| 7949 | debug_unregister(qeth_dbf_sense); |
| 7950 | if (qeth_dbf_misc) |
| 7951 | debug_unregister(qeth_dbf_misc); |
| 7952 | if (qeth_dbf_data) |
| 7953 | debug_unregister(qeth_dbf_data); |
| 7954 | if (qeth_dbf_control) |
| 7955 | debug_unregister(qeth_dbf_control); |
| 7956 | if (qeth_dbf_trace) |
| 7957 | debug_unregister(qeth_dbf_trace); |
| 7958 | } |
| 7959 | static int |
| 7960 | qeth_register_dbf_views(void) |
| 7961 | { |
| 7962 | qeth_dbf_setup = debug_register(QETH_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7963 | QETH_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7964 | QETH_DBF_SETUP_NR_AREAS, |
| 7965 | QETH_DBF_SETUP_LEN); |
| 7966 | qeth_dbf_misc = debug_register(QETH_DBF_MISC_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7967 | QETH_DBF_MISC_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7968 | QETH_DBF_MISC_NR_AREAS, |
| 7969 | QETH_DBF_MISC_LEN); |
| 7970 | qeth_dbf_data = debug_register(QETH_DBF_DATA_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7971 | QETH_DBF_DATA_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7972 | QETH_DBF_DATA_NR_AREAS, |
| 7973 | QETH_DBF_DATA_LEN); |
| 7974 | qeth_dbf_control = debug_register(QETH_DBF_CONTROL_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7975 | QETH_DBF_CONTROL_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7976 | QETH_DBF_CONTROL_NR_AREAS, |
| 7977 | QETH_DBF_CONTROL_LEN); |
| 7978 | qeth_dbf_sense = debug_register(QETH_DBF_SENSE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7979 | QETH_DBF_SENSE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7980 | QETH_DBF_SENSE_NR_AREAS, |
| 7981 | QETH_DBF_SENSE_LEN); |
| 7982 | qeth_dbf_qerr = debug_register(QETH_DBF_QERR_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7983 | QETH_DBF_QERR_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7984 | QETH_DBF_QERR_NR_AREAS, |
| 7985 | QETH_DBF_QERR_LEN); |
| 7986 | qeth_dbf_trace = debug_register(QETH_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 7987 | QETH_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7988 | QETH_DBF_TRACE_NR_AREAS, |
| 7989 | QETH_DBF_TRACE_LEN); |
| 7990 | |
| 7991 | if ((qeth_dbf_setup == NULL) || (qeth_dbf_misc == NULL) || |
| 7992 | (qeth_dbf_data == NULL) || (qeth_dbf_control == NULL) || |
| 7993 | (qeth_dbf_sense == NULL) || (qeth_dbf_qerr == NULL) || |
| 7994 | (qeth_dbf_trace == NULL)) { |
| 7995 | qeth_unregister_dbf_views(); |
| 7996 | return -ENOMEM; |
| 7997 | } |
| 7998 | debug_register_view(qeth_dbf_setup, &debug_hex_ascii_view); |
| 7999 | debug_set_level(qeth_dbf_setup, QETH_DBF_SETUP_LEVEL); |
| 8000 | |
| 8001 | debug_register_view(qeth_dbf_misc, &debug_hex_ascii_view); |
| 8002 | debug_set_level(qeth_dbf_misc, QETH_DBF_MISC_LEVEL); |
| 8003 | |
| 8004 | debug_register_view(qeth_dbf_data, &debug_hex_ascii_view); |
| 8005 | debug_set_level(qeth_dbf_data, QETH_DBF_DATA_LEVEL); |
| 8006 | |
| 8007 | debug_register_view(qeth_dbf_control, &debug_hex_ascii_view); |
| 8008 | debug_set_level(qeth_dbf_control, QETH_DBF_CONTROL_LEVEL); |
| 8009 | |
| 8010 | debug_register_view(qeth_dbf_sense, &debug_hex_ascii_view); |
| 8011 | debug_set_level(qeth_dbf_sense, QETH_DBF_SENSE_LEVEL); |
| 8012 | |
| 8013 | debug_register_view(qeth_dbf_qerr, &debug_hex_ascii_view); |
| 8014 | debug_set_level(qeth_dbf_qerr, QETH_DBF_QERR_LEVEL); |
| 8015 | |
| 8016 | debug_register_view(qeth_dbf_trace, &debug_hex_ascii_view); |
| 8017 | debug_set_level(qeth_dbf_trace, QETH_DBF_TRACE_LEVEL); |
| 8018 | |
| 8019 | return 0; |
| 8020 | } |
| 8021 | |
| 8022 | #ifdef CONFIG_QETH_IPV6 |
| 8023 | extern struct neigh_table arp_tbl; |
| 8024 | static struct neigh_ops *arp_direct_ops; |
| 8025 | static int (*qeth_old_arp_constructor) (struct neighbour *); |
| 8026 | |
| 8027 | static struct neigh_ops arp_direct_ops_template = { |
| 8028 | .family = AF_INET, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8029 | .solicit = NULL, |
| 8030 | .error_report = NULL, |
| 8031 | .output = dev_queue_xmit, |
| 8032 | .connected_output = dev_queue_xmit, |
| 8033 | .hh_output = dev_queue_xmit, |
| 8034 | .queue_xmit = dev_queue_xmit |
| 8035 | }; |
| 8036 | |
| 8037 | static int |
| 8038 | qeth_arp_constructor(struct neighbour *neigh) |
| 8039 | { |
| 8040 | struct net_device *dev = neigh->dev; |
| 8041 | struct in_device *in_dev; |
| 8042 | struct neigh_parms *parms; |
| 8043 | struct qeth_card *card; |
| 8044 | |
| 8045 | card = qeth_get_card_from_dev(dev); |
| 8046 | if (card == NULL) |
| 8047 | goto out; |
| 8048 | if((card->options.layer2) || |
| 8049 | (card->dev->hard_header == qeth_fake_header)) |
| 8050 | goto out; |
| 8051 | |
| 8052 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 8053 | in_dev = __in_dev_get_rcu(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8054 | if (in_dev == NULL) { |
| 8055 | rcu_read_unlock(); |
| 8056 | return -EINVAL; |
| 8057 | } |
| 8058 | |
| 8059 | parms = in_dev->arp_parms; |
| 8060 | __neigh_parms_put(neigh->parms); |
| 8061 | neigh->parms = neigh_parms_clone(parms); |
| 8062 | rcu_read_unlock(); |
| 8063 | |
| 8064 | neigh->type = inet_addr_type(*(u32 *) neigh->primary_key); |
| 8065 | neigh->nud_state = NUD_NOARP; |
| 8066 | neigh->ops = arp_direct_ops; |
| 8067 | neigh->output = neigh->ops->queue_xmit; |
| 8068 | return 0; |
| 8069 | out: |
| 8070 | return qeth_old_arp_constructor(neigh); |
| 8071 | } |
| 8072 | #endif /*CONFIG_QETH_IPV6*/ |
| 8073 | |
| 8074 | /* |
| 8075 | * IP address takeover related functions |
| 8076 | */ |
| 8077 | static void |
| 8078 | qeth_clear_ipato_list(struct qeth_card *card) |
| 8079 | { |
| 8080 | struct qeth_ipato_entry *ipatoe, *tmp; |
| 8081 | unsigned long flags; |
| 8082 | |
| 8083 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8084 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { |
| 8085 | list_del(&ipatoe->entry); |
| 8086 | kfree(ipatoe); |
| 8087 | } |
| 8088 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8089 | } |
| 8090 | |
| 8091 | int |
| 8092 | qeth_add_ipato_entry(struct qeth_card *card, struct qeth_ipato_entry *new) |
| 8093 | { |
| 8094 | struct qeth_ipato_entry *ipatoe; |
| 8095 | unsigned long flags; |
| 8096 | int rc = 0; |
| 8097 | |
| 8098 | QETH_DBF_TEXT(trace, 2, "addipato"); |
| 8099 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8100 | list_for_each_entry(ipatoe, &card->ipato.entries, entry){ |
| 8101 | if (ipatoe->proto != new->proto) |
| 8102 | continue; |
| 8103 | if (!memcmp(ipatoe->addr, new->addr, |
| 8104 | (ipatoe->proto == QETH_PROT_IPV4)? 4:16) && |
| 8105 | (ipatoe->mask_bits == new->mask_bits)){ |
| 8106 | PRINT_WARN("ipato entry already exists!\n"); |
| 8107 | rc = -EEXIST; |
| 8108 | break; |
| 8109 | } |
| 8110 | } |
| 8111 | if (!rc) { |
| 8112 | list_add_tail(&new->entry, &card->ipato.entries); |
| 8113 | } |
| 8114 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8115 | return rc; |
| 8116 | } |
| 8117 | |
| 8118 | void |
| 8119 | qeth_del_ipato_entry(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8120 | u8 *addr, int mask_bits) |
| 8121 | { |
| 8122 | struct qeth_ipato_entry *ipatoe, *tmp; |
| 8123 | unsigned long flags; |
| 8124 | |
| 8125 | QETH_DBF_TEXT(trace, 2, "delipato"); |
| 8126 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8127 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry){ |
| 8128 | if (ipatoe->proto != proto) |
| 8129 | continue; |
| 8130 | if (!memcmp(ipatoe->addr, addr, |
| 8131 | (proto == QETH_PROT_IPV4)? 4:16) && |
| 8132 | (ipatoe->mask_bits == mask_bits)){ |
| 8133 | list_del(&ipatoe->entry); |
| 8134 | kfree(ipatoe); |
| 8135 | } |
| 8136 | } |
| 8137 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8138 | } |
| 8139 | |
| 8140 | static inline void |
| 8141 | qeth_convert_addr_to_bits(u8 *addr, u8 *bits, int len) |
| 8142 | { |
| 8143 | int i, j; |
| 8144 | u8 octet; |
| 8145 | |
| 8146 | for (i = 0; i < len; ++i){ |
| 8147 | octet = addr[i]; |
| 8148 | for (j = 7; j >= 0; --j){ |
| 8149 | bits[i*8 + j] = octet & 1; |
| 8150 | octet >>= 1; |
| 8151 | } |
| 8152 | } |
| 8153 | } |
| 8154 | |
| 8155 | static int |
| 8156 | qeth_is_addr_covered_by_ipato(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 8157 | { |
| 8158 | struct qeth_ipato_entry *ipatoe; |
| 8159 | u8 addr_bits[128] = {0, }; |
| 8160 | u8 ipatoe_bits[128] = {0, }; |
| 8161 | int rc = 0; |
| 8162 | |
| 8163 | if (!card->ipato.enabled) |
| 8164 | return 0; |
| 8165 | |
| 8166 | qeth_convert_addr_to_bits((u8 *) &addr->u, addr_bits, |
| 8167 | (addr->proto == QETH_PROT_IPV4)? 4:16); |
| 8168 | list_for_each_entry(ipatoe, &card->ipato.entries, entry){ |
| 8169 | if (addr->proto != ipatoe->proto) |
| 8170 | continue; |
| 8171 | qeth_convert_addr_to_bits(ipatoe->addr, ipatoe_bits, |
| 8172 | (ipatoe->proto==QETH_PROT_IPV4) ? |
| 8173 | 4:16); |
| 8174 | if (addr->proto == QETH_PROT_IPV4) |
| 8175 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 8176 | min(32, ipatoe->mask_bits)); |
| 8177 | else |
| 8178 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 8179 | min(128, ipatoe->mask_bits)); |
| 8180 | if (rc) |
| 8181 | break; |
| 8182 | } |
| 8183 | /* invert? */ |
| 8184 | if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4) |
| 8185 | rc = !rc; |
| 8186 | else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6) |
| 8187 | rc = !rc; |
| 8188 | |
| 8189 | return rc; |
| 8190 | } |
| 8191 | |
| 8192 | /* |
| 8193 | * VIPA related functions |
| 8194 | */ |
| 8195 | int |
| 8196 | qeth_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8197 | const u8 *addr) |
| 8198 | { |
| 8199 | struct qeth_ipaddr *ipaddr; |
| 8200 | unsigned long flags; |
| 8201 | int rc = 0; |
| 8202 | |
| 8203 | ipaddr = qeth_get_addr_buffer(proto); |
| 8204 | if (ipaddr){ |
| 8205 | if (proto == QETH_PROT_IPV4){ |
| 8206 | QETH_DBF_TEXT(trace, 2, "addvipa4"); |
| 8207 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8208 | ipaddr->u.a4.mask = 0; |
| 8209 | #ifdef CONFIG_QETH_IPV6 |
| 8210 | } else if (proto == QETH_PROT_IPV6){ |
| 8211 | QETH_DBF_TEXT(trace, 2, "addvipa6"); |
| 8212 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8213 | ipaddr->u.a6.pfxlen = 0; |
| 8214 | #endif |
| 8215 | } |
| 8216 | ipaddr->type = QETH_IP_TYPE_VIPA; |
| 8217 | ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG; |
| 8218 | ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG; |
| 8219 | } else |
| 8220 | return -ENOMEM; |
| 8221 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8222 | if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) || |
| 8223 | __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0)) |
| 8224 | rc = -EEXIST; |
| 8225 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8226 | if (rc){ |
| 8227 | PRINT_WARN("Cannot add VIPA. Address already exists!\n"); |
| 8228 | return rc; |
| 8229 | } |
| 8230 | if (!qeth_add_ip(card, ipaddr)) |
| 8231 | kfree(ipaddr); |
| 8232 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8233 | schedule_work(&card->kernel_thread_starter); |
| 8234 | return rc; |
| 8235 | } |
| 8236 | |
| 8237 | void |
| 8238 | qeth_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8239 | const u8 *addr) |
| 8240 | { |
| 8241 | struct qeth_ipaddr *ipaddr; |
| 8242 | |
| 8243 | ipaddr = qeth_get_addr_buffer(proto); |
| 8244 | if (ipaddr){ |
| 8245 | if (proto == QETH_PROT_IPV4){ |
| 8246 | QETH_DBF_TEXT(trace, 2, "delvipa4"); |
| 8247 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8248 | ipaddr->u.a4.mask = 0; |
| 8249 | #ifdef CONFIG_QETH_IPV6 |
| 8250 | } else if (proto == QETH_PROT_IPV6){ |
| 8251 | QETH_DBF_TEXT(trace, 2, "delvipa6"); |
| 8252 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8253 | ipaddr->u.a6.pfxlen = 0; |
| 8254 | #endif |
| 8255 | } |
| 8256 | ipaddr->type = QETH_IP_TYPE_VIPA; |
| 8257 | } else |
| 8258 | return; |
| 8259 | if (!qeth_delete_ip(card, ipaddr)) |
| 8260 | kfree(ipaddr); |
| 8261 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8262 | schedule_work(&card->kernel_thread_starter); |
| 8263 | } |
| 8264 | |
| 8265 | /* |
| 8266 | * proxy ARP related functions |
| 8267 | */ |
| 8268 | int |
| 8269 | qeth_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8270 | const u8 *addr) |
| 8271 | { |
| 8272 | struct qeth_ipaddr *ipaddr; |
| 8273 | unsigned long flags; |
| 8274 | int rc = 0; |
| 8275 | |
| 8276 | ipaddr = qeth_get_addr_buffer(proto); |
| 8277 | if (ipaddr){ |
| 8278 | if (proto == QETH_PROT_IPV4){ |
| 8279 | QETH_DBF_TEXT(trace, 2, "addrxip4"); |
| 8280 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8281 | ipaddr->u.a4.mask = 0; |
| 8282 | #ifdef CONFIG_QETH_IPV6 |
| 8283 | } else if (proto == QETH_PROT_IPV6){ |
| 8284 | QETH_DBF_TEXT(trace, 2, "addrxip6"); |
| 8285 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8286 | ipaddr->u.a6.pfxlen = 0; |
| 8287 | #endif |
| 8288 | } |
| 8289 | ipaddr->type = QETH_IP_TYPE_RXIP; |
| 8290 | ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG; |
| 8291 | ipaddr->del_flags = 0; |
| 8292 | } else |
| 8293 | return -ENOMEM; |
| 8294 | spin_lock_irqsave(&card->ip_lock, flags); |
| 8295 | if (__qeth_address_exists_in_list(&card->ip_list, ipaddr, 0) || |
| 8296 | __qeth_address_exists_in_list(card->ip_tbd_list, ipaddr, 0)) |
| 8297 | rc = -EEXIST; |
| 8298 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 8299 | if (rc){ |
| 8300 | PRINT_WARN("Cannot add RXIP. Address already exists!\n"); |
| 8301 | return rc; |
| 8302 | } |
| 8303 | if (!qeth_add_ip(card, ipaddr)) |
| 8304 | kfree(ipaddr); |
| 8305 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8306 | schedule_work(&card->kernel_thread_starter); |
| 8307 | return 0; |
| 8308 | } |
| 8309 | |
| 8310 | void |
| 8311 | qeth_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto, |
| 8312 | const u8 *addr) |
| 8313 | { |
| 8314 | struct qeth_ipaddr *ipaddr; |
| 8315 | |
| 8316 | ipaddr = qeth_get_addr_buffer(proto); |
| 8317 | if (ipaddr){ |
| 8318 | if (proto == QETH_PROT_IPV4){ |
| 8319 | QETH_DBF_TEXT(trace, 2, "addrxip4"); |
| 8320 | memcpy(&ipaddr->u.a4.addr, addr, 4); |
| 8321 | ipaddr->u.a4.mask = 0; |
| 8322 | #ifdef CONFIG_QETH_IPV6 |
| 8323 | } else if (proto == QETH_PROT_IPV6){ |
| 8324 | QETH_DBF_TEXT(trace, 2, "addrxip6"); |
| 8325 | memcpy(&ipaddr->u.a6.addr, addr, 16); |
| 8326 | ipaddr->u.a6.pfxlen = 0; |
| 8327 | #endif |
| 8328 | } |
| 8329 | ipaddr->type = QETH_IP_TYPE_RXIP; |
| 8330 | } else |
| 8331 | return; |
| 8332 | if (!qeth_delete_ip(card, ipaddr)) |
| 8333 | kfree(ipaddr); |
| 8334 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8335 | schedule_work(&card->kernel_thread_starter); |
| 8336 | } |
| 8337 | |
| 8338 | /** |
| 8339 | * IP event handler |
| 8340 | */ |
| 8341 | static int |
| 8342 | qeth_ip_event(struct notifier_block *this, |
| 8343 | unsigned long event,void *ptr) |
| 8344 | { |
| 8345 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 8346 | struct net_device *dev =(struct net_device *) ifa->ifa_dev->dev; |
| 8347 | struct qeth_ipaddr *addr; |
| 8348 | struct qeth_card *card; |
| 8349 | |
| 8350 | QETH_DBF_TEXT(trace,3,"ipevent"); |
| 8351 | card = qeth_get_card_from_dev(dev); |
| 8352 | if (!card) |
| 8353 | return NOTIFY_DONE; |
| 8354 | if (card->options.layer2) |
| 8355 | return NOTIFY_DONE; |
| 8356 | |
| 8357 | addr = qeth_get_addr_buffer(QETH_PROT_IPV4); |
| 8358 | if (addr != NULL) { |
| 8359 | addr->u.a4.addr = ifa->ifa_address; |
| 8360 | addr->u.a4.mask = ifa->ifa_mask; |
| 8361 | addr->type = QETH_IP_TYPE_NORMAL; |
| 8362 | } else |
| 8363 | goto out; |
| 8364 | |
| 8365 | switch(event) { |
| 8366 | case NETDEV_UP: |
| 8367 | if (!qeth_add_ip(card, addr)) |
| 8368 | kfree(addr); |
| 8369 | break; |
| 8370 | case NETDEV_DOWN: |
| 8371 | if (!qeth_delete_ip(card, addr)) |
| 8372 | kfree(addr); |
| 8373 | break; |
| 8374 | default: |
| 8375 | break; |
| 8376 | } |
| 8377 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8378 | schedule_work(&card->kernel_thread_starter); |
| 8379 | out: |
| 8380 | return NOTIFY_DONE; |
| 8381 | } |
| 8382 | |
| 8383 | static struct notifier_block qeth_ip_notifier = { |
| 8384 | qeth_ip_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8385 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8386 | }; |
| 8387 | |
| 8388 | #ifdef CONFIG_QETH_IPV6 |
| 8389 | /** |
| 8390 | * IPv6 event handler |
| 8391 | */ |
| 8392 | static int |
| 8393 | qeth_ip6_event(struct notifier_block *this, |
| 8394 | unsigned long event,void *ptr) |
| 8395 | { |
| 8396 | |
| 8397 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
| 8398 | struct net_device *dev = (struct net_device *)ifa->idev->dev; |
| 8399 | struct qeth_ipaddr *addr; |
| 8400 | struct qeth_card *card; |
| 8401 | |
| 8402 | QETH_DBF_TEXT(trace,3,"ip6event"); |
| 8403 | |
| 8404 | card = qeth_get_card_from_dev(dev); |
| 8405 | if (!card) |
| 8406 | return NOTIFY_DONE; |
| 8407 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 8408 | return NOTIFY_DONE; |
| 8409 | |
| 8410 | addr = qeth_get_addr_buffer(QETH_PROT_IPV6); |
| 8411 | if (addr != NULL) { |
| 8412 | memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr)); |
| 8413 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 8414 | addr->type = QETH_IP_TYPE_NORMAL; |
| 8415 | } else |
| 8416 | goto out; |
| 8417 | |
| 8418 | switch(event) { |
| 8419 | case NETDEV_UP: |
| 8420 | if (!qeth_add_ip(card, addr)) |
| 8421 | kfree(addr); |
| 8422 | break; |
| 8423 | case NETDEV_DOWN: |
| 8424 | if (!qeth_delete_ip(card, addr)) |
| 8425 | kfree(addr); |
| 8426 | break; |
| 8427 | default: |
| 8428 | break; |
| 8429 | } |
| 8430 | if (qeth_set_thread_start_bit(card, QETH_SET_IP_THREAD) == 0) |
| 8431 | schedule_work(&card->kernel_thread_starter); |
| 8432 | out: |
| 8433 | return NOTIFY_DONE; |
| 8434 | } |
| 8435 | |
| 8436 | static struct notifier_block qeth_ip6_notifier = { |
| 8437 | qeth_ip6_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8438 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8439 | }; |
| 8440 | #endif |
| 8441 | |
| 8442 | static int |
Cornelia Huck | 66aea23 | 2005-08-08 09:22:36 -0700 | [diff] [blame] | 8443 | __qeth_reboot_event_card(struct device *dev, void *data) |
| 8444 | { |
| 8445 | struct qeth_card *card; |
| 8446 | |
| 8447 | card = (struct qeth_card *) dev->driver_data; |
| 8448 | qeth_clear_ip_list(card, 0, 0); |
| 8449 | qeth_qdio_clear_card(card, 0); |
| 8450 | return 0; |
| 8451 | } |
| 8452 | |
| 8453 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8454 | qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 8455 | { |
Heiko Carstens | d7cf0d5 | 2006-07-18 13:46:58 +0200 | [diff] [blame] | 8456 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8457 | |
Heiko Carstens | d7cf0d5 | 2006-07-18 13:46:58 +0200 | [diff] [blame] | 8458 | ret = driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL, |
| 8459 | __qeth_reboot_event_card); |
| 8460 | return ret ? NOTIFY_BAD : NOTIFY_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8461 | } |
| 8462 | |
| 8463 | |
| 8464 | static struct notifier_block qeth_reboot_notifier = { |
| 8465 | qeth_reboot_event, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 8466 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8467 | }; |
| 8468 | |
| 8469 | static int |
| 8470 | qeth_register_notifiers(void) |
| 8471 | { |
| 8472 | int r; |
| 8473 | |
| 8474 | QETH_DBF_TEXT(trace,5,"regnotif"); |
| 8475 | if ((r = register_reboot_notifier(&qeth_reboot_notifier))) |
| 8476 | return r; |
| 8477 | if ((r = register_inetaddr_notifier(&qeth_ip_notifier))) |
| 8478 | goto out_reboot; |
| 8479 | #ifdef CONFIG_QETH_IPV6 |
| 8480 | if ((r = register_inet6addr_notifier(&qeth_ip6_notifier))) |
| 8481 | goto out_ipv4; |
| 8482 | #endif |
| 8483 | return 0; |
| 8484 | |
| 8485 | #ifdef CONFIG_QETH_IPV6 |
| 8486 | out_ipv4: |
| 8487 | unregister_inetaddr_notifier(&qeth_ip_notifier); |
| 8488 | #endif |
| 8489 | out_reboot: |
| 8490 | unregister_reboot_notifier(&qeth_reboot_notifier); |
| 8491 | return r; |
| 8492 | } |
| 8493 | |
| 8494 | /** |
| 8495 | * unregister all event notifiers |
| 8496 | */ |
| 8497 | static void |
| 8498 | qeth_unregister_notifiers(void) |
| 8499 | { |
| 8500 | |
| 8501 | QETH_DBF_TEXT(trace,5,"unregnot"); |
| 8502 | BUG_ON(unregister_reboot_notifier(&qeth_reboot_notifier)); |
| 8503 | BUG_ON(unregister_inetaddr_notifier(&qeth_ip_notifier)); |
| 8504 | #ifdef CONFIG_QETH_IPV6 |
| 8505 | BUG_ON(unregister_inet6addr_notifier(&qeth_ip6_notifier)); |
| 8506 | #endif /* QETH_IPV6 */ |
| 8507 | |
| 8508 | } |
| 8509 | |
| 8510 | #ifdef CONFIG_QETH_IPV6 |
| 8511 | static int |
| 8512 | qeth_ipv6_init(void) |
| 8513 | { |
| 8514 | qeth_old_arp_constructor = arp_tbl.constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame] | 8515 | write_lock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8516 | arp_tbl.constructor = qeth_arp_constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame] | 8517 | write_unlock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8518 | |
| 8519 | arp_direct_ops = (struct neigh_ops*) |
| 8520 | kmalloc(sizeof(struct neigh_ops), GFP_KERNEL); |
| 8521 | if (!arp_direct_ops) |
| 8522 | return -ENOMEM; |
| 8523 | |
| 8524 | memcpy(arp_direct_ops, &arp_direct_ops_template, |
| 8525 | sizeof(struct neigh_ops)); |
| 8526 | |
| 8527 | return 0; |
| 8528 | } |
| 8529 | |
| 8530 | static void |
| 8531 | qeth_ipv6_uninit(void) |
| 8532 | { |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame] | 8533 | write_lock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8534 | arp_tbl.constructor = qeth_old_arp_constructor; |
Heiko Carstens | 3d8f3f3 | 2006-08-14 23:00:27 -0700 | [diff] [blame] | 8535 | write_unlock_bh(&arp_tbl.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8536 | kfree(arp_direct_ops); |
| 8537 | } |
| 8538 | #endif /* CONFIG_QETH_IPV6 */ |
| 8539 | |
| 8540 | static void |
| 8541 | qeth_sysfs_unregister(void) |
| 8542 | { |
| 8543 | qeth_remove_driver_attributes(); |
| 8544 | ccw_driver_unregister(&qeth_ccw_driver); |
| 8545 | ccwgroup_driver_unregister(&qeth_ccwgroup_driver); |
| 8546 | s390_root_dev_unregister(qeth_root_dev); |
| 8547 | } |
| 8548 | /** |
| 8549 | * register qeth at sysfs |
| 8550 | */ |
| 8551 | static int |
| 8552 | qeth_sysfs_register(void) |
| 8553 | { |
| 8554 | int rc=0; |
| 8555 | |
| 8556 | rc = ccwgroup_driver_register(&qeth_ccwgroup_driver); |
| 8557 | if (rc) |
| 8558 | return rc; |
| 8559 | rc = ccw_driver_register(&qeth_ccw_driver); |
| 8560 | if (rc) |
| 8561 | return rc; |
| 8562 | rc = qeth_create_driver_attributes(); |
| 8563 | if (rc) |
| 8564 | return rc; |
| 8565 | qeth_root_dev = s390_root_dev_register("qeth"); |
| 8566 | if (IS_ERR(qeth_root_dev)) { |
| 8567 | rc = PTR_ERR(qeth_root_dev); |
| 8568 | return rc; |
| 8569 | } |
| 8570 | return 0; |
| 8571 | } |
| 8572 | |
| 8573 | /*** |
| 8574 | * init function |
| 8575 | */ |
| 8576 | static int __init |
| 8577 | qeth_init(void) |
| 8578 | { |
| 8579 | int rc=0; |
| 8580 | |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 8581 | PRINT_INFO("loading %s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8582 | |
| 8583 | INIT_LIST_HEAD(&qeth_card_list.list); |
| 8584 | INIT_LIST_HEAD(&qeth_notify_list); |
| 8585 | spin_lock_init(&qeth_notify_lock); |
| 8586 | rwlock_init(&qeth_card_list.rwlock); |
| 8587 | |
| 8588 | if (qeth_register_dbf_views()) |
| 8589 | goto out_err; |
| 8590 | if (qeth_sysfs_register()) |
| 8591 | goto out_sysfs; |
| 8592 | |
| 8593 | #ifdef CONFIG_QETH_IPV6 |
| 8594 | if (qeth_ipv6_init()) { |
| 8595 | PRINT_ERR("Out of memory during ipv6 init.\n"); |
| 8596 | goto out_sysfs; |
| 8597 | } |
| 8598 | #endif /* QETH_IPV6 */ |
| 8599 | if (qeth_register_notifiers()) |
| 8600 | goto out_ipv6; |
| 8601 | if (qeth_create_procfs_entries()) |
| 8602 | goto out_notifiers; |
| 8603 | |
| 8604 | return rc; |
| 8605 | |
| 8606 | out_notifiers: |
| 8607 | qeth_unregister_notifiers(); |
| 8608 | out_ipv6: |
| 8609 | #ifdef CONFIG_QETH_IPV6 |
| 8610 | qeth_ipv6_uninit(); |
| 8611 | #endif /* QETH_IPV6 */ |
| 8612 | out_sysfs: |
| 8613 | qeth_sysfs_unregister(); |
| 8614 | qeth_unregister_dbf_views(); |
| 8615 | out_err: |
| 8616 | PRINT_ERR("Initialization failed"); |
| 8617 | return rc; |
| 8618 | } |
| 8619 | |
| 8620 | static void |
| 8621 | __exit qeth_exit(void) |
| 8622 | { |
| 8623 | struct qeth_card *card, *tmp; |
| 8624 | unsigned long flags; |
| 8625 | |
| 8626 | QETH_DBF_TEXT(trace,1, "cleanup."); |
| 8627 | |
| 8628 | /* |
| 8629 | * Weed would not need to clean up our devices here, because the |
| 8630 | * common device layer calls qeth_remove_device for each device |
| 8631 | * as soon as we unregister our driver (done in qeth_sysfs_unregister). |
| 8632 | * But we do cleanup here so we can do a "soft" shutdown of our cards. |
| 8633 | * qeth_remove_device called by the common device layer would otherwise |
| 8634 | * do a "hard" shutdown (card->use_hard_stop is set to one in |
| 8635 | * qeth_remove_device). |
| 8636 | */ |
| 8637 | again: |
| 8638 | read_lock_irqsave(&qeth_card_list.rwlock, flags); |
| 8639 | list_for_each_entry_safe(card, tmp, &qeth_card_list.list, list){ |
| 8640 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 8641 | qeth_set_offline(card->gdev); |
| 8642 | qeth_remove_device(card->gdev); |
| 8643 | goto again; |
| 8644 | } |
| 8645 | read_unlock_irqrestore(&qeth_card_list.rwlock, flags); |
| 8646 | #ifdef CONFIG_QETH_IPV6 |
| 8647 | qeth_ipv6_uninit(); |
| 8648 | #endif |
| 8649 | qeth_unregister_notifiers(); |
| 8650 | qeth_remove_procfs_entries(); |
| 8651 | qeth_sysfs_unregister(); |
| 8652 | qeth_unregister_dbf_views(); |
| 8653 | printk("qeth: removed\n"); |
| 8654 | } |
| 8655 | |
Ursula Braun | 500f83a | 2005-09-30 10:19:19 +0200 | [diff] [blame] | 8656 | EXPORT_SYMBOL(qeth_osn_register); |
| 8657 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 8658 | EXPORT_SYMBOL(qeth_osn_assist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8659 | module_init(qeth_init); |
| 8660 | module_exit(qeth_exit); |
Frank Pavlic | 1387780f | 2005-11-10 13:51:42 +0100 | [diff] [blame] | 8661 | MODULE_AUTHOR("Frank Pavlic <fpavlic@de.ibm.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8662 | MODULE_DESCRIPTION("Linux on zSeries OSA Express and HiperSockets support\n" \ |
| 8663 | "Copyright 2000,2003 IBM Corporation\n"); |
| 8664 | |
| 8665 | MODULE_LICENSE("GPL"); |