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