2 * drivers/s390/net/qeth_core_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/tcp.h>
21 #include <linux/mii.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <net/iucv/af_iucv.h>
26 #include <asm/ebcdic.h>
28 #include <asm/sysinfo.h>
30 #include "qeth_core.h"
32 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
33 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
35 [QETH_DBF_SETUP
] = {"qeth_setup",
36 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
37 [QETH_DBF_MSG
] = {"qeth_msg",
38 8, 1, 128, 3, &debug_sprintf_view
, NULL
},
39 [QETH_DBF_CTRL
] = {"qeth_control",
40 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
42 EXPORT_SYMBOL_GPL(qeth_dbf
);
44 struct qeth_card_list_struct qeth_core_card_list
;
45 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
46 struct kmem_cache
*qeth_core_header_cache
;
47 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
48 static struct kmem_cache
*qeth_qdio_outbuf_cache
;
50 static struct device
*qeth_core_root_dev
;
51 static unsigned int known_devices
[][6] = QETH_MODELLIST_ARRAY
;
52 static struct lock_class_key qdio_out_skb_queue_key
;
54 static void qeth_send_control_data_cb(struct qeth_channel
*,
55 struct qeth_cmd_buffer
*);
56 static int qeth_issue_next_read(struct qeth_card
*);
57 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
58 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
59 static void qeth_free_buffer_pool(struct qeth_card
*);
60 static int qeth_qdio_establish(struct qeth_card
*);
61 static void qeth_free_qdio_buffers(struct qeth_card
*);
62 static void qeth_notify_skbs(struct qeth_qdio_out_q
*queue
,
63 struct qeth_qdio_out_buffer
*buf
,
64 enum iucv_tx_notify notification
);
65 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
);
66 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
67 struct qeth_qdio_out_buffer
*buf
,
68 enum qeth_qdio_buffer_states newbufstate
);
71 static inline const char *qeth_get_cardname(struct qeth_card
*card
)
73 if (card
->info
.guestlan
) {
74 switch (card
->info
.type
) {
75 case QETH_CARD_TYPE_OSD
:
76 return " Guest LAN QDIO";
77 case QETH_CARD_TYPE_IQD
:
78 return " Guest LAN Hiper";
79 case QETH_CARD_TYPE_OSM
:
80 return " Guest LAN QDIO - OSM";
81 case QETH_CARD_TYPE_OSX
:
82 return " Guest LAN QDIO - OSX";
87 switch (card
->info
.type
) {
88 case QETH_CARD_TYPE_OSD
:
89 return " OSD Express";
90 case QETH_CARD_TYPE_IQD
:
91 return " HiperSockets";
92 case QETH_CARD_TYPE_OSN
:
94 case QETH_CARD_TYPE_OSM
:
96 case QETH_CARD_TYPE_OSX
:
105 /* max length to be returned: 14 */
106 const char *qeth_get_cardname_short(struct qeth_card
*card
)
108 if (card
->info
.guestlan
) {
109 switch (card
->info
.type
) {
110 case QETH_CARD_TYPE_OSD
:
111 return "GuestLAN QDIO";
112 case QETH_CARD_TYPE_IQD
:
113 return "GuestLAN Hiper";
114 case QETH_CARD_TYPE_OSM
:
115 return "GuestLAN OSM";
116 case QETH_CARD_TYPE_OSX
:
117 return "GuestLAN OSX";
122 switch (card
->info
.type
) {
123 case QETH_CARD_TYPE_OSD
:
124 switch (card
->info
.link_type
) {
125 case QETH_LINK_TYPE_FAST_ETH
:
127 case QETH_LINK_TYPE_HSTR
:
129 case QETH_LINK_TYPE_GBIT_ETH
:
131 case QETH_LINK_TYPE_10GBIT_ETH
:
133 case QETH_LINK_TYPE_LANE_ETH100
:
134 return "OSD_FE_LANE";
135 case QETH_LINK_TYPE_LANE_TR
:
136 return "OSD_TR_LANE";
137 case QETH_LINK_TYPE_LANE_ETH1000
:
138 return "OSD_GbE_LANE";
139 case QETH_LINK_TYPE_LANE
:
140 return "OSD_ATM_LANE";
142 return "OSD_Express";
144 case QETH_CARD_TYPE_IQD
:
145 return "HiperSockets";
146 case QETH_CARD_TYPE_OSN
:
148 case QETH_CARD_TYPE_OSM
:
150 case QETH_CARD_TYPE_OSX
:
159 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
160 int clear_start_mask
)
164 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
165 card
->thread_allowed_mask
= threads
;
166 if (clear_start_mask
)
167 card
->thread_start_mask
&= threads
;
168 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
169 wake_up(&card
->wait_q
);
171 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
173 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
178 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
179 rc
= (card
->thread_running_mask
& threads
);
180 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
183 EXPORT_SYMBOL_GPL(qeth_threads_running
);
185 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
187 return wait_event_interruptible(card
->wait_q
,
188 qeth_threads_running(card
, threads
) == 0);
190 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
192 void qeth_clear_working_pool_list(struct qeth_card
*card
)
194 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
196 QETH_CARD_TEXT(card
, 5, "clwrklst");
197 list_for_each_entry_safe(pool_entry
, tmp
,
198 &card
->qdio
.in_buf_pool
.entry_list
, list
){
199 list_del(&pool_entry
->list
);
202 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
204 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
206 struct qeth_buffer_pool_entry
*pool_entry
;
210 QETH_CARD_TEXT(card
, 5, "alocpool");
211 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
212 pool_entry
= kzalloc(sizeof(*pool_entry
), GFP_KERNEL
);
214 qeth_free_buffer_pool(card
);
217 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
218 ptr
= (void *) __get_free_page(GFP_KERNEL
);
221 free_page((unsigned long)
222 pool_entry
->elements
[--j
]);
224 qeth_free_buffer_pool(card
);
227 pool_entry
->elements
[j
] = ptr
;
229 list_add(&pool_entry
->init_list
,
230 &card
->qdio
.init_pool
.entry_list
);
235 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
237 QETH_CARD_TEXT(card
, 2, "realcbp");
239 if ((card
->state
!= CARD_STATE_DOWN
) &&
240 (card
->state
!= CARD_STATE_RECOVER
))
243 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
244 qeth_clear_working_pool_list(card
);
245 qeth_free_buffer_pool(card
);
246 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
247 card
->qdio
.init_pool
.buf_count
= bufcnt
;
248 return qeth_alloc_buffer_pool(card
);
250 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
252 static inline int qeth_cq_init(struct qeth_card
*card
)
256 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
257 QETH_DBF_TEXT(SETUP
, 2, "cqinit");
258 memset(card
->qdio
.c_q
->qdio_bufs
, 0,
259 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
260 card
->qdio
.c_q
->next_buf_to_init
= 127;
261 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
,
262 card
->qdio
.no_in_queues
- 1, 0,
265 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
274 static inline int qeth_alloc_cq(struct qeth_card
*card
)
278 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
280 struct qdio_outbuf_state
*outbuf_states
;
282 QETH_DBF_TEXT(SETUP
, 2, "cqon");
283 card
->qdio
.c_q
= kzalloc(sizeof(struct qeth_qdio_q
),
285 if (!card
->qdio
.c_q
) {
289 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.c_q
, sizeof(void *));
291 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
292 card
->qdio
.c_q
->bufs
[i
].buffer
=
293 &card
->qdio
.c_q
->qdio_bufs
[i
];
296 card
->qdio
.no_in_queues
= 2;
298 card
->qdio
.out_bufstates
= (struct qdio_outbuf_state
*)
299 kzalloc(card
->qdio
.no_out_queues
*
300 QDIO_MAX_BUFFERS_PER_Q
*
301 sizeof(struct qdio_outbuf_state
), GFP_KERNEL
);
302 outbuf_states
= card
->qdio
.out_bufstates
;
303 if (outbuf_states
== NULL
) {
307 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
308 card
->qdio
.out_qs
[i
]->bufstates
= outbuf_states
;
309 outbuf_states
+= QDIO_MAX_BUFFERS_PER_Q
;
312 QETH_DBF_TEXT(SETUP
, 2, "nocq");
313 card
->qdio
.c_q
= NULL
;
314 card
->qdio
.no_in_queues
= 1;
316 QETH_DBF_TEXT_(SETUP
, 2, "iqc%d", card
->qdio
.no_in_queues
);
321 kfree(card
->qdio
.c_q
);
322 card
->qdio
.c_q
= NULL
;
324 dev_err(&card
->gdev
->dev
, "Failed to create completion queue\n");
328 static inline void qeth_free_cq(struct qeth_card
*card
)
330 if (card
->qdio
.c_q
) {
331 --card
->qdio
.no_in_queues
;
332 kfree(card
->qdio
.c_q
);
333 card
->qdio
.c_q
= NULL
;
335 kfree(card
->qdio
.out_bufstates
);
336 card
->qdio
.out_bufstates
= NULL
;
339 static inline enum iucv_tx_notify
qeth_compute_cq_notification(int sbalf15
,
341 enum iucv_tx_notify n
;
345 n
= delayed
? TX_NOTIFY_DELAYED_OK
: TX_NOTIFY_OK
;
351 n
= delayed
? TX_NOTIFY_DELAYED_UNREACHABLE
:
352 TX_NOTIFY_UNREACHABLE
;
355 n
= delayed
? TX_NOTIFY_DELAYED_GENERALERROR
:
356 TX_NOTIFY_GENERALERROR
;
363 static inline void qeth_cleanup_handled_pending(struct qeth_qdio_out_q
*q
,
364 int bidx
, int forced_cleanup
)
366 if (q
->bufs
[bidx
]->next_pending
!= NULL
) {
367 struct qeth_qdio_out_buffer
*head
= q
->bufs
[bidx
];
368 struct qeth_qdio_out_buffer
*c
= q
->bufs
[bidx
]->next_pending
;
371 if (forced_cleanup
||
372 atomic_read(&c
->state
) ==
373 QETH_QDIO_BUF_HANDLED_DELAYED
) {
374 struct qeth_qdio_out_buffer
*f
= c
;
375 QETH_CARD_TEXT(f
->q
->card
, 5, "fp");
376 QETH_CARD_TEXT_(f
->q
->card
, 5, "%lx", (long) f
);
377 /* release here to avoid interleaving between
378 outbound tasklet and inbound tasklet
379 regarding notifications and lifecycle */
380 qeth_release_skbs(c
);
383 BUG_ON(head
->next_pending
!= f
);
384 head
->next_pending
= c
;
385 kmem_cache_free(qeth_qdio_outbuf_cache
, f
);
396 static inline void qeth_qdio_handle_aob(struct qeth_card
*card
,
397 unsigned long phys_aob_addr
) {
399 struct qeth_qdio_out_buffer
*buffer
;
400 enum iucv_tx_notify notification
;
402 aob
= (struct qaob
*) phys_to_virt(phys_aob_addr
);
403 QETH_CARD_TEXT(card
, 5, "haob");
404 QETH_CARD_TEXT_(card
, 5, "%lx", phys_aob_addr
);
405 buffer
= (struct qeth_qdio_out_buffer
*) aob
->user1
;
406 QETH_CARD_TEXT_(card
, 5, "%lx", aob
->user1
);
408 BUG_ON(buffer
== NULL
);
410 if (atomic_cmpxchg(&buffer
->state
, QETH_QDIO_BUF_PRIMED
,
411 QETH_QDIO_BUF_IN_CQ
) == QETH_QDIO_BUF_PRIMED
) {
412 notification
= TX_NOTIFY_OK
;
414 BUG_ON(atomic_read(&buffer
->state
) != QETH_QDIO_BUF_PENDING
);
416 atomic_set(&buffer
->state
, QETH_QDIO_BUF_IN_CQ
);
417 notification
= TX_NOTIFY_DELAYED_OK
;
420 if (aob
->aorc
!= 0) {
421 QETH_CARD_TEXT_(card
, 2, "aorc%02X", aob
->aorc
);
422 notification
= qeth_compute_cq_notification(aob
->aorc
, 1);
424 qeth_notify_skbs(buffer
->q
, buffer
, notification
);
427 qeth_clear_output_buffer(buffer
->q
, buffer
,
428 QETH_QDIO_BUF_HANDLED_DELAYED
);
429 /* from here on: do not touch buffer anymore */
430 qdio_release_aob(aob
);
433 static inline int qeth_is_cq(struct qeth_card
*card
, unsigned int queue
)
435 return card
->options
.cq
== QETH_CQ_ENABLED
&&
436 card
->qdio
.c_q
!= NULL
&&
438 queue
== card
->qdio
.no_in_queues
- 1;
442 static int qeth_issue_next_read(struct qeth_card
*card
)
445 struct qeth_cmd_buffer
*iob
;
447 QETH_CARD_TEXT(card
, 5, "issnxrd");
448 if (card
->read
.state
!= CH_STATE_UP
)
450 iob
= qeth_get_buffer(&card
->read
);
452 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
453 "failed to recover an error on the device\n");
454 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
455 "available\n", dev_name(&card
->gdev
->dev
));
458 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
459 QETH_CARD_TEXT(card
, 6, "noirqpnd");
460 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
463 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
464 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
465 atomic_set(&card
->read
.irq_pending
, 0);
466 card
->read_or_write_problem
= 1;
467 qeth_schedule_recovery(card
);
468 wake_up(&card
->wait_q
);
473 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
475 struct qeth_reply
*reply
;
477 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
479 atomic_set(&reply
->refcnt
, 1);
480 atomic_set(&reply
->received
, 0);
486 static void qeth_get_reply(struct qeth_reply
*reply
)
488 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
489 atomic_inc(&reply
->refcnt
);
492 static void qeth_put_reply(struct qeth_reply
*reply
)
494 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
495 if (atomic_dec_and_test(&reply
->refcnt
))
499 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
500 struct qeth_card
*card
)
503 int com
= cmd
->hdr
.command
;
504 ipa_name
= qeth_get_ipa_cmd_name(com
);
506 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
508 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
509 QETH_CARD_IFNAME(card
), rc
,
510 qeth_get_ipa_msg(rc
));
512 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
513 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
514 QETH_CARD_IFNAME(card
));
517 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
518 struct qeth_cmd_buffer
*iob
)
520 struct qeth_ipa_cmd
*cmd
= NULL
;
522 QETH_CARD_TEXT(card
, 5, "chkipad");
523 if (IS_IPA(iob
->data
)) {
524 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
525 if (IS_IPA_REPLY(cmd
)) {
526 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
527 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
528 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
529 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
530 qeth_issue_ipa_msg(cmd
,
531 cmd
->hdr
.return_code
, card
);
534 switch (cmd
->hdr
.command
) {
535 case IPA_CMD_STOPLAN
:
536 dev_warn(&card
->gdev
->dev
,
537 "The link for interface %s on CHPID"
539 QETH_CARD_IFNAME(card
),
541 card
->lan_online
= 0;
542 if (card
->dev
&& netif_carrier_ok(card
->dev
))
543 netif_carrier_off(card
->dev
);
545 case IPA_CMD_STARTLAN
:
546 dev_info(&card
->gdev
->dev
,
547 "The link for %s on CHPID 0x%X has"
549 QETH_CARD_IFNAME(card
),
551 netif_carrier_on(card
->dev
);
552 card
->lan_online
= 1;
553 if (card
->info
.hwtrap
)
554 card
->info
.hwtrap
= 2;
555 qeth_schedule_recovery(card
);
557 case IPA_CMD_MODCCID
:
559 case IPA_CMD_REGISTER_LOCAL_ADDR
:
560 QETH_CARD_TEXT(card
, 3, "irla");
562 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
563 QETH_CARD_TEXT(card
, 3, "urla");
566 QETH_DBF_MESSAGE(2, "Received data is IPA "
567 "but not a reply!\n");
575 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
577 struct qeth_reply
*reply
, *r
;
580 QETH_CARD_TEXT(card
, 4, "clipalst");
582 spin_lock_irqsave(&card
->lock
, flags
);
583 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
584 qeth_get_reply(reply
);
586 atomic_inc(&reply
->received
);
587 list_del_init(&reply
->list
);
588 wake_up(&reply
->wait_q
);
589 qeth_put_reply(reply
);
591 spin_unlock_irqrestore(&card
->lock
, flags
);
592 atomic_set(&card
->write
.irq_pending
, 0);
594 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
596 static int qeth_check_idx_response(struct qeth_card
*card
,
597 unsigned char *buffer
)
602 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
603 if ((buffer
[2] & 0xc0) == 0xc0) {
604 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
605 "with cause code 0x%02x%s\n",
607 ((buffer
[4] == 0x22) ?
608 " -- try another portname" : ""));
609 QETH_CARD_TEXT(card
, 2, "ckidxres");
610 QETH_CARD_TEXT(card
, 2, " idxterm");
611 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
612 if (buffer
[4] == 0xf6) {
613 dev_err(&card
->gdev
->dev
,
614 "The qeth device is not configured "
615 "for the OSI layer required by z/VM\n");
623 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
626 struct qeth_card
*card
;
628 card
= CARD_FROM_CDEV(channel
->ccwdev
);
629 QETH_CARD_TEXT(card
, 4, "setupccw");
630 if (channel
== &card
->read
)
631 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
633 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
634 channel
->ccw
.count
= len
;
635 channel
->ccw
.cda
= (__u32
) __pa(iob
);
638 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
642 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "getbuff");
643 index
= channel
->io_buf_no
;
645 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
646 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
647 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
649 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
650 return channel
->iob
+ index
;
652 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
653 } while (index
!= channel
->io_buf_no
);
658 void qeth_release_buffer(struct qeth_channel
*channel
,
659 struct qeth_cmd_buffer
*iob
)
663 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "relbuff");
664 spin_lock_irqsave(&channel
->iob_lock
, flags
);
665 memset(iob
->data
, 0, QETH_BUFSIZE
);
666 iob
->state
= BUF_STATE_FREE
;
667 iob
->callback
= qeth_send_control_data_cb
;
669 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
671 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
673 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
675 struct qeth_cmd_buffer
*buffer
= NULL
;
678 spin_lock_irqsave(&channel
->iob_lock
, flags
);
679 buffer
= __qeth_get_buffer(channel
);
680 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
684 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
686 struct qeth_cmd_buffer
*buffer
;
687 wait_event(channel
->wait_q
,
688 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
691 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
693 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
697 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
698 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
700 channel
->io_buf_no
= 0;
702 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
704 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
705 struct qeth_cmd_buffer
*iob
)
707 struct qeth_card
*card
;
708 struct qeth_reply
*reply
, *r
;
709 struct qeth_ipa_cmd
*cmd
;
714 card
= CARD_FROM_CDEV(channel
->ccwdev
);
715 QETH_CARD_TEXT(card
, 4, "sndctlcb");
716 rc
= qeth_check_idx_response(card
, iob
->data
);
721 qeth_clear_ipacmd_list(card
);
722 qeth_schedule_recovery(card
);
728 cmd
= qeth_check_ipa_data(card
, iob
);
729 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
731 /*in case of OSN : check if cmd is set */
732 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
734 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
735 card
->osn_info
.assist_cb
!= NULL
) {
736 card
->osn_info
.assist_cb(card
->dev
, cmd
);
740 spin_lock_irqsave(&card
->lock
, flags
);
741 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
742 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
743 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
744 qeth_get_reply(reply
);
745 list_del_init(&reply
->list
);
746 spin_unlock_irqrestore(&card
->lock
, flags
);
748 if (reply
->callback
!= NULL
) {
750 reply
->offset
= (__u16
)((char *)cmd
-
752 keep_reply
= reply
->callback(card
,
756 keep_reply
= reply
->callback(card
,
761 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
765 spin_lock_irqsave(&card
->lock
, flags
);
766 list_add_tail(&reply
->list
,
767 &card
->cmd_waiter_list
);
768 spin_unlock_irqrestore(&card
->lock
, flags
);
770 atomic_inc(&reply
->received
);
771 wake_up(&reply
->wait_q
);
773 qeth_put_reply(reply
);
777 spin_unlock_irqrestore(&card
->lock
, flags
);
779 memcpy(&card
->seqno
.pdu_hdr_ack
,
780 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
782 qeth_release_buffer(channel
, iob
);
785 static int qeth_setup_channel(struct qeth_channel
*channel
)
789 QETH_DBF_TEXT(SETUP
, 2, "setupch");
790 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
791 channel
->iob
[cnt
].data
=
792 kzalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
793 if (channel
->iob
[cnt
].data
== NULL
)
795 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
796 channel
->iob
[cnt
].channel
= channel
;
797 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
798 channel
->iob
[cnt
].rc
= 0;
800 if (cnt
< QETH_CMD_BUFFER_NO
) {
802 kfree(channel
->iob
[cnt
].data
);
806 channel
->io_buf_no
= 0;
807 atomic_set(&channel
->irq_pending
, 0);
808 spin_lock_init(&channel
->iob_lock
);
810 init_waitqueue_head(&channel
->wait_q
);
814 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
815 unsigned long thread
)
819 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
820 if (!(card
->thread_allowed_mask
& thread
) ||
821 (card
->thread_start_mask
& thread
)) {
822 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
825 card
->thread_start_mask
|= thread
;
826 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
830 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
834 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
835 card
->thread_start_mask
&= ~thread
;
836 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
837 wake_up(&card
->wait_q
);
839 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
841 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
845 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
846 card
->thread_running_mask
&= ~thread
;
847 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
848 wake_up(&card
->wait_q
);
850 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
852 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
857 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
858 if (card
->thread_start_mask
& thread
) {
859 if ((card
->thread_allowed_mask
& thread
) &&
860 !(card
->thread_running_mask
& thread
)) {
862 card
->thread_start_mask
&= ~thread
;
863 card
->thread_running_mask
|= thread
;
867 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
871 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
875 wait_event(card
->wait_q
,
876 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
879 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
881 void qeth_schedule_recovery(struct qeth_card
*card
)
883 QETH_CARD_TEXT(card
, 2, "startrec");
885 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
886 schedule_work(&card
->kernel_thread_starter
);
888 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
890 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
894 struct qeth_card
*card
;
896 sense
= (char *) irb
->ecw
;
897 cstat
= irb
->scsw
.cmd
.cstat
;
898 dstat
= irb
->scsw
.cmd
.dstat
;
899 card
= CARD_FROM_CDEV(cdev
);
901 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
902 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
903 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
904 QETH_CARD_TEXT(card
, 2, "CGENCHK");
905 dev_warn(&cdev
->dev
, "The qeth device driver "
906 "failed to recover an error on the device\n");
907 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
908 dev_name(&cdev
->dev
), dstat
, cstat
);
909 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
914 if (dstat
& DEV_STAT_UNIT_CHECK
) {
915 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
916 SENSE_RESETTING_EVENT_FLAG
) {
917 QETH_CARD_TEXT(card
, 2, "REVIND");
920 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
921 SENSE_COMMAND_REJECT_FLAG
) {
922 QETH_CARD_TEXT(card
, 2, "CMDREJi");
925 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
926 QETH_CARD_TEXT(card
, 2, "AFFE");
929 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
930 QETH_CARD_TEXT(card
, 2, "ZEROSEN");
933 QETH_CARD_TEXT(card
, 2, "DGENCHK");
939 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
940 unsigned long intparm
, struct irb
*irb
)
942 struct qeth_card
*card
;
944 card
= CARD_FROM_CDEV(cdev
);
949 switch (PTR_ERR(irb
)) {
951 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
952 dev_name(&cdev
->dev
));
953 QETH_CARD_TEXT(card
, 2, "ckirberr");
954 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
957 dev_warn(&cdev
->dev
, "A hardware operation timed out"
959 QETH_CARD_TEXT(card
, 2, "ckirberr");
960 QETH_CARD_TEXT_(card
, 2, " rc%d", -ETIMEDOUT
);
961 if (intparm
== QETH_RCD_PARM
) {
962 if (card
&& (card
->data
.ccwdev
== cdev
)) {
963 card
->data
.state
= CH_STATE_DOWN
;
964 wake_up(&card
->wait_q
);
969 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
970 dev_name(&cdev
->dev
), PTR_ERR(irb
));
971 QETH_CARD_TEXT(card
, 2, "ckirberr");
972 QETH_CARD_TEXT(card
, 2, " rc???");
977 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
982 struct qeth_cmd_buffer
*buffer
;
983 struct qeth_channel
*channel
;
984 struct qeth_card
*card
;
985 struct qeth_cmd_buffer
*iob
;
988 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
990 cstat
= irb
->scsw
.cmd
.cstat
;
991 dstat
= irb
->scsw
.cmd
.dstat
;
993 card
= CARD_FROM_CDEV(cdev
);
997 QETH_CARD_TEXT(card
, 5, "irq");
999 if (card
->read
.ccwdev
== cdev
) {
1000 channel
= &card
->read
;
1001 QETH_CARD_TEXT(card
, 5, "read");
1002 } else if (card
->write
.ccwdev
== cdev
) {
1003 channel
= &card
->write
;
1004 QETH_CARD_TEXT(card
, 5, "write");
1006 channel
= &card
->data
;
1007 QETH_CARD_TEXT(card
, 5, "data");
1009 atomic_set(&channel
->irq_pending
, 0);
1011 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
1012 channel
->state
= CH_STATE_STOPPED
;
1014 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
1015 channel
->state
= CH_STATE_HALTED
;
1017 /*let's wake up immediately on data channel*/
1018 if ((channel
== &card
->data
) && (intparm
!= 0) &&
1019 (intparm
!= QETH_RCD_PARM
))
1022 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
1023 QETH_CARD_TEXT(card
, 6, "clrchpar");
1024 /* we don't have to handle this further */
1027 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
1028 QETH_CARD_TEXT(card
, 6, "hltchpar");
1029 /* we don't have to handle this further */
1032 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
1033 (dstat
& DEV_STAT_UNIT_CHECK
) ||
1035 if (irb
->esw
.esw0
.erw
.cons
) {
1036 dev_warn(&channel
->ccwdev
->dev
,
1037 "The qeth device driver failed to recover "
1038 "an error on the device\n");
1039 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1040 "0x%X dstat 0x%X\n",
1041 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
1042 print_hex_dump(KERN_WARNING
, "qeth: irb ",
1043 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
1044 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
1045 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
1047 if (intparm
== QETH_RCD_PARM
) {
1048 channel
->state
= CH_STATE_DOWN
;
1051 rc
= qeth_get_problem(cdev
, irb
);
1053 qeth_clear_ipacmd_list(card
);
1054 qeth_schedule_recovery(card
);
1059 if (intparm
== QETH_RCD_PARM
) {
1060 channel
->state
= CH_STATE_RCD_DONE
;
1064 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
1065 buffer
->state
= BUF_STATE_PROCESSED
;
1067 if (channel
== &card
->data
)
1069 if (channel
== &card
->read
&&
1070 channel
->state
== CH_STATE_UP
)
1071 qeth_issue_next_read(card
);
1074 index
= channel
->buf_no
;
1075 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
1076 if (iob
[index
].callback
!= NULL
)
1077 iob
[index
].callback(channel
, iob
+ index
);
1079 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
1081 channel
->buf_no
= index
;
1083 wake_up(&card
->wait_q
);
1087 static void qeth_notify_skbs(struct qeth_qdio_out_q
*q
,
1088 struct qeth_qdio_out_buffer
*buf
,
1089 enum iucv_tx_notify notification
)
1091 struct sk_buff
*skb
;
1093 if (skb_queue_empty(&buf
->skb_list
))
1095 skb
= skb_peek(&buf
->skb_list
);
1097 QETH_CARD_TEXT_(q
->card
, 5, "skbn%d", notification
);
1098 QETH_CARD_TEXT_(q
->card
, 5, "%lx", (long) skb
);
1099 if (skb
->protocol
== ETH_P_AF_IUCV
) {
1101 struct iucv_sock
*iucv
= iucv_sk(skb
->sk
);
1102 iucv
->sk_txnotify(skb
, notification
);
1105 if (skb_queue_is_last(&buf
->skb_list
, skb
))
1108 skb
= skb_queue_next(&buf
->skb_list
, skb
);
1114 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
)
1116 struct sk_buff
*skb
;
1118 skb
= skb_dequeue(&buf
->skb_list
);
1120 QETH_CARD_TEXT(buf
->q
->card
, 5, "skbr");
1121 QETH_CARD_TEXT_(buf
->q
->card
, 5, "%lx", (long) skb
);
1122 atomic_dec(&skb
->users
);
1123 dev_kfree_skb_any(skb
);
1124 skb
= skb_dequeue(&buf
->skb_list
);
1128 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
1129 struct qeth_qdio_out_buffer
*buf
,
1130 enum qeth_qdio_buffer_states newbufstate
)
1134 /* is PCI flag set on buffer? */
1135 if (buf
->buffer
->element
[0].sflags
& SBAL_SFLAGS0_PCI_REQ
)
1136 atomic_dec(&queue
->set_pci_flags_count
);
1138 if (newbufstate
== QETH_QDIO_BUF_EMPTY
) {
1139 qeth_release_skbs(buf
);
1141 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
1142 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
1143 kmem_cache_free(qeth_core_header_cache
,
1144 buf
->buffer
->element
[i
].addr
);
1145 buf
->is_header
[i
] = 0;
1146 buf
->buffer
->element
[i
].length
= 0;
1147 buf
->buffer
->element
[i
].addr
= NULL
;
1148 buf
->buffer
->element
[i
].eflags
= 0;
1149 buf
->buffer
->element
[i
].sflags
= 0;
1151 buf
->buffer
->element
[15].eflags
= 0;
1152 buf
->buffer
->element
[15].sflags
= 0;
1153 buf
->next_element_to_fill
= 0;
1154 atomic_set(&buf
->state
, newbufstate
);
1157 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q
*q
, int free
)
1161 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1164 qeth_cleanup_handled_pending(q
, j
, free
);
1165 qeth_clear_output_buffer(q
, q
->bufs
[j
], QETH_QDIO_BUF_EMPTY
);
1167 kmem_cache_free(qeth_qdio_outbuf_cache
, q
->bufs
[j
]);
1173 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
1177 QETH_CARD_TEXT(card
, 2, "clearqdbf");
1178 /* clear outbound buffers to free skbs */
1179 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1180 if (card
->qdio
.out_qs
[i
]) {
1181 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 0);
1185 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
1187 static void qeth_free_buffer_pool(struct qeth_card
*card
)
1189 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
1191 list_for_each_entry_safe(pool_entry
, tmp
,
1192 &card
->qdio
.init_pool
.entry_list
, init_list
){
1193 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
1194 free_page((unsigned long)pool_entry
->elements
[i
]);
1195 list_del(&pool_entry
->init_list
);
1200 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
1204 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
1205 QETH_QDIO_UNINITIALIZED
)
1209 cancel_delayed_work_sync(&card
->buffer_reclaim_work
);
1210 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
)
1211 kfree_skb(card
->qdio
.in_q
->bufs
[j
].rx_skb
);
1212 kfree(card
->qdio
.in_q
);
1213 card
->qdio
.in_q
= NULL
;
1214 /* inbound buffer pool */
1215 qeth_free_buffer_pool(card
);
1216 /* free outbound qdio_qs */
1217 if (card
->qdio
.out_qs
) {
1218 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1219 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
1220 kfree(card
->qdio
.out_qs
[i
]);
1222 kfree(card
->qdio
.out_qs
);
1223 card
->qdio
.out_qs
= NULL
;
1227 static void qeth_clean_channel(struct qeth_channel
*channel
)
1231 QETH_DBF_TEXT(SETUP
, 2, "freech");
1232 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1233 kfree(channel
->iob
[cnt
].data
);
1236 static void qeth_get_channel_path_desc(struct qeth_card
*card
)
1238 struct ccw_device
*ccwdev
;
1239 struct channelPath_dsc
{
1250 QETH_DBF_TEXT(SETUP
, 2, "chp_desc");
1252 ccwdev
= card
->data
.ccwdev
;
1253 chp_dsc
= (struct channelPath_dsc
*)ccw_device_get_chp_desc(ccwdev
, 0);
1254 if (chp_dsc
!= NULL
) {
1255 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
1256 /* CHPP field bit 6 == 1 -> single queue */
1257 if ((chp_dsc
->chpp
& 0x02) == 0x02) {
1258 if ((atomic_read(&card
->qdio
.state
) !=
1259 QETH_QDIO_UNINITIALIZED
) &&
1260 (card
->qdio
.no_out_queues
== 4))
1261 /* change from 4 to 1 outbound queues */
1262 qeth_free_qdio_buffers(card
);
1263 card
->qdio
.no_out_queues
= 1;
1264 if (card
->qdio
.default_out_queue
!= 0)
1265 dev_info(&card
->gdev
->dev
,
1266 "Priority Queueing not supported\n");
1267 card
->qdio
.default_out_queue
= 0;
1269 if ((atomic_read(&card
->qdio
.state
) !=
1270 QETH_QDIO_UNINITIALIZED
) &&
1271 (card
->qdio
.no_out_queues
== 1)) {
1272 /* change from 1 to 4 outbound queues */
1273 qeth_free_qdio_buffers(card
);
1274 card
->qdio
.default_out_queue
= 2;
1276 card
->qdio
.no_out_queues
= 4;
1279 card
->info
.func_level
= 0x4100 + chp_dsc
->desc
;
1282 QETH_DBF_TEXT_(SETUP
, 2, "nr:%x", card
->qdio
.no_out_queues
);
1283 QETH_DBF_TEXT_(SETUP
, 2, "lvl:%02x", card
->info
.func_level
);
1287 static void qeth_init_qdio_info(struct qeth_card
*card
)
1289 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1290 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1292 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1293 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1294 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_HSDEFAULT
;
1296 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1297 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1298 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1299 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1302 static void qeth_set_intial_options(struct qeth_card
*card
)
1304 card
->options
.route4
.type
= NO_ROUTER
;
1305 card
->options
.route6
.type
= NO_ROUTER
;
1306 card
->options
.broadcast_mode
= QETH_TR_BROADCAST_ALLRINGS
;
1307 card
->options
.macaddr_mode
= QETH_TR_MACADDR_NONCANONICAL
;
1308 card
->options
.fake_broadcast
= 0;
1309 card
->options
.add_hhlen
= DEFAULT_ADD_HHLEN
;
1310 card
->options
.performance_stats
= 0;
1311 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1312 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1313 card
->options
.cq
= QETH_CQ_DISABLED
;
1316 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1318 unsigned long flags
;
1321 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1322 QETH_CARD_TEXT_(card
, 4, " %02x%02x%02x",
1323 (u8
) card
->thread_start_mask
,
1324 (u8
) card
->thread_allowed_mask
,
1325 (u8
) card
->thread_running_mask
);
1326 rc
= (card
->thread_start_mask
& thread
);
1327 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1331 static void qeth_start_kernel_thread(struct work_struct
*work
)
1333 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1334 kernel_thread_starter
);
1335 QETH_CARD_TEXT(card
, 2, "strthrd");
1337 if (card
->read
.state
!= CH_STATE_UP
&&
1338 card
->write
.state
!= CH_STATE_UP
)
1340 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
))
1341 kthread_run(card
->discipline
.recover
, (void *) card
,
1345 static int qeth_setup_card(struct qeth_card
*card
)
1348 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1349 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1351 card
->read
.state
= CH_STATE_DOWN
;
1352 card
->write
.state
= CH_STATE_DOWN
;
1353 card
->data
.state
= CH_STATE_DOWN
;
1354 card
->state
= CARD_STATE_DOWN
;
1355 card
->lan_online
= 0;
1356 card
->read_or_write_problem
= 0;
1358 spin_lock_init(&card
->vlanlock
);
1359 spin_lock_init(&card
->mclock
);
1360 spin_lock_init(&card
->lock
);
1361 spin_lock_init(&card
->ip_lock
);
1362 spin_lock_init(&card
->thread_mask_lock
);
1363 mutex_init(&card
->conf_mutex
);
1364 mutex_init(&card
->discipline_mutex
);
1365 card
->thread_start_mask
= 0;
1366 card
->thread_allowed_mask
= 0;
1367 card
->thread_running_mask
= 0;
1368 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1369 INIT_LIST_HEAD(&card
->ip_list
);
1370 INIT_LIST_HEAD(card
->ip_tbd_list
);
1371 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1372 init_waitqueue_head(&card
->wait_q
);
1373 /* initial options */
1374 qeth_set_intial_options(card
);
1375 /* IP address takeover */
1376 INIT_LIST_HEAD(&card
->ipato
.entries
);
1377 card
->ipato
.enabled
= 0;
1378 card
->ipato
.invert4
= 0;
1379 card
->ipato
.invert6
= 0;
1380 /* init QDIO stuff */
1381 qeth_init_qdio_info(card
);
1382 INIT_DELAYED_WORK(&card
->buffer_reclaim_work
, qeth_buffer_reclaim_work
);
1386 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1388 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1389 qeth_service_level
);
1390 if (card
->info
.mcl_level
[0])
1391 seq_printf(m
, "qeth: %s firmware level %s\n",
1392 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1395 static struct qeth_card
*qeth_alloc_card(void)
1397 struct qeth_card
*card
;
1399 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1400 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1403 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1404 card
->ip_tbd_list
= kzalloc(sizeof(struct list_head
), GFP_KERNEL
);
1405 if (!card
->ip_tbd_list
) {
1406 QETH_DBF_TEXT(SETUP
, 0, "iptbdnom");
1409 if (qeth_setup_channel(&card
->read
))
1411 if (qeth_setup_channel(&card
->write
))
1413 card
->options
.layer2
= -1;
1414 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1415 register_service_level(&card
->qeth_service_level
);
1419 qeth_clean_channel(&card
->read
);
1421 kfree(card
->ip_tbd_list
);
1428 static int qeth_determine_card_type(struct qeth_card
*card
)
1432 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1434 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1435 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1436 while (known_devices
[i
][QETH_DEV_MODEL_IND
]) {
1437 if ((CARD_RDEV(card
)->id
.dev_type
==
1438 known_devices
[i
][QETH_DEV_TYPE_IND
]) &&
1439 (CARD_RDEV(card
)->id
.dev_model
==
1440 known_devices
[i
][QETH_DEV_MODEL_IND
])) {
1441 card
->info
.type
= known_devices
[i
][QETH_DEV_MODEL_IND
];
1442 card
->qdio
.no_out_queues
=
1443 known_devices
[i
][QETH_QUEUE_NO_IND
];
1444 card
->qdio
.no_in_queues
= 1;
1445 card
->info
.is_multicast_different
=
1446 known_devices
[i
][QETH_MULTICAST_IND
];
1447 qeth_get_channel_path_desc(card
);
1452 card
->info
.type
= QETH_CARD_TYPE_UNKNOWN
;
1453 dev_err(&card
->gdev
->dev
, "The adapter hardware is of an "
1458 static int qeth_clear_channel(struct qeth_channel
*channel
)
1460 unsigned long flags
;
1461 struct qeth_card
*card
;
1464 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1465 QETH_CARD_TEXT(card
, 3, "clearch");
1466 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1467 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1468 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1472 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1473 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1474 if (rc
== -ERESTARTSYS
)
1476 if (channel
->state
!= CH_STATE_STOPPED
)
1478 channel
->state
= CH_STATE_DOWN
;
1482 static int qeth_halt_channel(struct qeth_channel
*channel
)
1484 unsigned long flags
;
1485 struct qeth_card
*card
;
1488 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1489 QETH_CARD_TEXT(card
, 3, "haltch");
1490 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1491 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1492 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1496 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1497 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1498 if (rc
== -ERESTARTSYS
)
1500 if (channel
->state
!= CH_STATE_HALTED
)
1505 static int qeth_halt_channels(struct qeth_card
*card
)
1507 int rc1
= 0, rc2
= 0, rc3
= 0;
1509 QETH_CARD_TEXT(card
, 3, "haltchs");
1510 rc1
= qeth_halt_channel(&card
->read
);
1511 rc2
= qeth_halt_channel(&card
->write
);
1512 rc3
= qeth_halt_channel(&card
->data
);
1520 static int qeth_clear_channels(struct qeth_card
*card
)
1522 int rc1
= 0, rc2
= 0, rc3
= 0;
1524 QETH_CARD_TEXT(card
, 3, "clearchs");
1525 rc1
= qeth_clear_channel(&card
->read
);
1526 rc2
= qeth_clear_channel(&card
->write
);
1527 rc3
= qeth_clear_channel(&card
->data
);
1535 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1539 QETH_CARD_TEXT(card
, 3, "clhacrd");
1542 rc
= qeth_halt_channels(card
);
1545 return qeth_clear_channels(card
);
1548 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1552 QETH_CARD_TEXT(card
, 3, "qdioclr");
1553 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1554 QETH_QDIO_CLEANING
)) {
1555 case QETH_QDIO_ESTABLISHED
:
1556 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1557 rc
= qdio_shutdown(CARD_DDEV(card
),
1558 QDIO_FLAG_CLEANUP_USING_HALT
);
1560 rc
= qdio_shutdown(CARD_DDEV(card
),
1561 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1563 QETH_CARD_TEXT_(card
, 3, "1err%d", rc
);
1564 qdio_free(CARD_DDEV(card
));
1565 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1567 case QETH_QDIO_CLEANING
:
1572 rc
= qeth_clear_halt_card(card
, use_halt
);
1574 QETH_CARD_TEXT_(card
, 3, "2err%d", rc
);
1575 card
->state
= CARD_STATE_DOWN
;
1578 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1580 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1586 struct qeth_channel
*channel
= &card
->data
;
1587 unsigned long flags
;
1590 * scan for RCD command in extended SenseID data
1592 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1593 if (!ciw
|| ciw
->cmd
== 0)
1595 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1599 channel
->ccw
.cmd_code
= ciw
->cmd
;
1600 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1601 channel
->ccw
.count
= ciw
->count
;
1602 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1603 channel
->state
= CH_STATE_RCD
;
1604 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1605 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1606 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1608 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1610 wait_event(card
->wait_q
,
1611 (channel
->state
== CH_STATE_RCD_DONE
||
1612 channel
->state
== CH_STATE_DOWN
));
1613 if (channel
->state
== CH_STATE_DOWN
)
1616 channel
->state
= CH_STATE_DOWN
;
1622 *length
= ciw
->count
;
1628 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1630 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1631 card
->info
.chpid
= prcd
[30];
1632 card
->info
.unit_addr2
= prcd
[31];
1633 card
->info
.cula
= prcd
[63];
1634 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1635 (prcd
[0x11] == _ascebc
['M']));
1638 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1640 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1642 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 && prcd
[76] == 0xF5) {
1643 card
->info
.blkt
.time_total
= 250;
1644 card
->info
.blkt
.inter_packet
= 5;
1645 card
->info
.blkt
.inter_packet_jumbo
= 15;
1647 card
->info
.blkt
.time_total
= 0;
1648 card
->info
.blkt
.inter_packet
= 0;
1649 card
->info
.blkt
.inter_packet_jumbo
= 0;
1653 static void qeth_init_tokens(struct qeth_card
*card
)
1655 card
->token
.issuer_rm_w
= 0x00010103UL
;
1656 card
->token
.cm_filter_w
= 0x00010108UL
;
1657 card
->token
.cm_connection_w
= 0x0001010aUL
;
1658 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1659 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1662 static void qeth_init_func_level(struct qeth_card
*card
)
1664 switch (card
->info
.type
) {
1665 case QETH_CARD_TYPE_IQD
:
1666 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_IQD
;
1668 case QETH_CARD_TYPE_OSD
:
1669 case QETH_CARD_TYPE_OSN
:
1670 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_OSD
;
1677 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1678 void (*idx_reply_cb
)(struct qeth_channel
*,
1679 struct qeth_cmd_buffer
*))
1681 struct qeth_cmd_buffer
*iob
;
1682 unsigned long flags
;
1684 struct qeth_card
*card
;
1686 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1687 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1688 iob
= qeth_get_buffer(channel
);
1689 iob
->callback
= idx_reply_cb
;
1690 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1691 channel
->ccw
.count
= QETH_BUFSIZE
;
1692 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1694 wait_event(card
->wait_q
,
1695 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1696 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1697 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1698 rc
= ccw_device_start(channel
->ccwdev
,
1699 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1700 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1703 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1704 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1705 atomic_set(&channel
->irq_pending
, 0);
1706 wake_up(&card
->wait_q
);
1709 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1710 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1711 if (rc
== -ERESTARTSYS
)
1713 if (channel
->state
!= CH_STATE_UP
) {
1715 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1716 qeth_clear_cmd_buffers(channel
);
1722 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1723 void (*idx_reply_cb
)(struct qeth_channel
*,
1724 struct qeth_cmd_buffer
*))
1726 struct qeth_card
*card
;
1727 struct qeth_cmd_buffer
*iob
;
1728 unsigned long flags
;
1732 struct ccw_dev_id temp_devid
;
1734 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1736 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1738 iob
= qeth_get_buffer(channel
);
1739 iob
->callback
= idx_reply_cb
;
1740 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1741 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1742 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1743 if (channel
== &card
->write
) {
1744 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1745 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1746 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1747 card
->seqno
.trans_hdr
++;
1749 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1750 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1751 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1753 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1754 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1755 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1756 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1757 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1758 &card
->info
.func_level
, sizeof(__u16
));
1759 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1760 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1761 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1762 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1764 wait_event(card
->wait_q
,
1765 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1766 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1767 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1768 rc
= ccw_device_start(channel
->ccwdev
,
1769 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1770 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1773 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1775 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1776 atomic_set(&channel
->irq_pending
, 0);
1777 wake_up(&card
->wait_q
);
1780 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1781 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1782 if (rc
== -ERESTARTSYS
)
1784 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1785 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1786 " failed to recover an error on the device\n");
1787 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1788 dev_name(&channel
->ccwdev
->dev
));
1789 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1790 qeth_clear_cmd_buffers(channel
);
1793 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1796 static int qeth_peer_func_level(int level
)
1798 if ((level
& 0xff) == 8)
1799 return (level
& 0xff) + 0x400;
1800 if (((level
>> 8) & 3) == 1)
1801 return (level
& 0xff) + 0x200;
1805 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1806 struct qeth_cmd_buffer
*iob
)
1808 struct qeth_card
*card
;
1811 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1813 if (channel
->state
== CH_STATE_DOWN
) {
1814 channel
->state
= CH_STATE_ACTIVATING
;
1817 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1819 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1820 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == QETH_IDX_ACT_ERR_EXCL
)
1821 dev_err(&card
->write
.ccwdev
->dev
,
1822 "The adapter is used exclusively by another "
1825 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1826 " negative reply\n",
1827 dev_name(&card
->write
.ccwdev
->dev
));
1830 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1831 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
1832 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1833 "function level mismatch (sent: 0x%x, received: "
1834 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
1835 card
->info
.func_level
, temp
);
1838 channel
->state
= CH_STATE_UP
;
1840 qeth_release_buffer(channel
, iob
);
1843 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
1844 struct qeth_cmd_buffer
*iob
)
1846 struct qeth_card
*card
;
1849 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
1850 if (channel
->state
== CH_STATE_DOWN
) {
1851 channel
->state
= CH_STATE_ACTIVATING
;
1855 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1856 if (qeth_check_idx_response(card
, iob
->data
))
1859 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1860 switch (QETH_IDX_ACT_CAUSE_CODE(iob
->data
)) {
1861 case QETH_IDX_ACT_ERR_EXCL
:
1862 dev_err(&card
->write
.ccwdev
->dev
,
1863 "The adapter is used exclusively by another "
1866 case QETH_IDX_ACT_ERR_AUTH
:
1867 case QETH_IDX_ACT_ERR_AUTH_USER
:
1868 dev_err(&card
->read
.ccwdev
->dev
,
1869 "Setting the device online failed because of "
1870 "insufficient authorization\n");
1873 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1874 " negative reply\n",
1875 dev_name(&card
->read
.ccwdev
->dev
));
1877 QETH_CARD_TEXT_(card
, 2, "idxread%c",
1878 QETH_IDX_ACT_CAUSE_CODE(iob
->data
));
1883 * * temporary fix for microcode bug
1884 * * to revert it,replace OR by AND
1886 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob
->data
)) ||
1887 (card
->info
.type
== QETH_CARD_TYPE_OSD
))
1888 card
->info
.portname_required
= 1;
1890 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1891 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
1892 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1893 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1894 dev_name(&card
->read
.ccwdev
->dev
),
1895 card
->info
.func_level
, temp
);
1898 memcpy(&card
->token
.issuer_rm_r
,
1899 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1900 QETH_MPC_TOKEN_LENGTH
);
1901 memcpy(&card
->info
.mcl_level
[0],
1902 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
1903 channel
->state
= CH_STATE_UP
;
1905 qeth_release_buffer(channel
, iob
);
1908 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
1909 struct qeth_cmd_buffer
*iob
)
1911 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
1912 iob
->callback
= qeth_release_buffer
;
1914 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1915 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1916 card
->seqno
.trans_hdr
++;
1917 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
1918 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
1919 card
->seqno
.pdu_hdr
++;
1920 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
1921 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
1922 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1924 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
1926 int qeth_send_control_data(struct qeth_card
*card
, int len
,
1927 struct qeth_cmd_buffer
*iob
,
1928 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1933 unsigned long flags
;
1934 struct qeth_reply
*reply
= NULL
;
1935 unsigned long timeout
, event_timeout
;
1936 struct qeth_ipa_cmd
*cmd
;
1938 QETH_CARD_TEXT(card
, 2, "sendctl");
1940 if (card
->read_or_write_problem
) {
1941 qeth_release_buffer(iob
->channel
, iob
);
1944 reply
= qeth_alloc_reply(card
);
1948 reply
->callback
= reply_cb
;
1949 reply
->param
= reply_param
;
1950 if (card
->state
== CARD_STATE_DOWN
)
1951 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
1953 reply
->seqno
= card
->seqno
.ipa
++;
1954 init_waitqueue_head(&reply
->wait_q
);
1955 spin_lock_irqsave(&card
->lock
, flags
);
1956 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
1957 spin_unlock_irqrestore(&card
->lock
, flags
);
1958 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1960 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
1961 qeth_prepare_control_data(card
, len
, iob
);
1963 if (IS_IPA(iob
->data
))
1964 event_timeout
= QETH_IPA_TIMEOUT
;
1966 event_timeout
= QETH_TIMEOUT
;
1967 timeout
= jiffies
+ event_timeout
;
1969 QETH_CARD_TEXT(card
, 6, "noirqpnd");
1970 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1971 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
1972 (addr_t
) iob
, 0, 0);
1973 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1975 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
1976 "ccw_device_start rc = %i\n",
1977 dev_name(&card
->write
.ccwdev
->dev
), rc
);
1978 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
1979 spin_lock_irqsave(&card
->lock
, flags
);
1980 list_del_init(&reply
->list
);
1981 qeth_put_reply(reply
);
1982 spin_unlock_irqrestore(&card
->lock
, flags
);
1983 qeth_release_buffer(iob
->channel
, iob
);
1984 atomic_set(&card
->write
.irq_pending
, 0);
1985 wake_up(&card
->wait_q
);
1989 /* we have only one long running ipassist, since we can ensure
1990 process context of this command we can sleep */
1991 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1992 if ((cmd
->hdr
.command
== IPA_CMD_SETIP
) &&
1993 (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)) {
1994 if (!wait_event_timeout(reply
->wait_q
,
1995 atomic_read(&reply
->received
), event_timeout
))
1998 while (!atomic_read(&reply
->received
)) {
1999 if (time_after(jiffies
, timeout
))
2005 if (reply
->rc
== -EIO
)
2008 qeth_put_reply(reply
);
2013 spin_lock_irqsave(&reply
->card
->lock
, flags
);
2014 list_del_init(&reply
->list
);
2015 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
2016 atomic_inc(&reply
->received
);
2018 atomic_set(&card
->write
.irq_pending
, 0);
2019 qeth_release_buffer(iob
->channel
, iob
);
2020 card
->write
.buf_no
= (card
->write
.buf_no
+ 1) % QETH_CMD_BUFFER_NO
;
2022 qeth_put_reply(reply
);
2025 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
2027 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2030 struct qeth_cmd_buffer
*iob
;
2032 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
2034 iob
= (struct qeth_cmd_buffer
*) data
;
2035 memcpy(&card
->token
.cm_filter_r
,
2036 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2037 QETH_MPC_TOKEN_LENGTH
);
2038 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2042 static int qeth_cm_enable(struct qeth_card
*card
)
2045 struct qeth_cmd_buffer
*iob
;
2047 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
2049 iob
= qeth_wait_for_buffer(&card
->write
);
2050 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
2051 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
2052 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2053 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
2054 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2056 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
2057 qeth_cm_enable_cb
, NULL
);
2061 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2065 struct qeth_cmd_buffer
*iob
;
2067 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
2069 iob
= (struct qeth_cmd_buffer
*) data
;
2070 memcpy(&card
->token
.cm_connection_r
,
2071 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
2072 QETH_MPC_TOKEN_LENGTH
);
2073 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2077 static int qeth_cm_setup(struct qeth_card
*card
)
2080 struct qeth_cmd_buffer
*iob
;
2082 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
2084 iob
= qeth_wait_for_buffer(&card
->write
);
2085 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
2086 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
2087 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2088 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
2089 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2090 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
2091 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2092 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
2093 qeth_cm_setup_cb
, NULL
);
2098 static inline int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
2100 switch (card
->info
.type
) {
2101 case QETH_CARD_TYPE_UNKNOWN
:
2103 case QETH_CARD_TYPE_IQD
:
2104 return card
->info
.max_mtu
;
2105 case QETH_CARD_TYPE_OSD
:
2106 switch (card
->info
.link_type
) {
2107 case QETH_LINK_TYPE_HSTR
:
2108 case QETH_LINK_TYPE_LANE_TR
:
2113 case QETH_CARD_TYPE_OSM
:
2114 case QETH_CARD_TYPE_OSX
:
2121 static inline int qeth_get_mtu_outof_framesize(int framesize
)
2123 switch (framesize
) {
2137 static inline int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
2139 switch (card
->info
.type
) {
2140 case QETH_CARD_TYPE_OSD
:
2141 case QETH_CARD_TYPE_OSM
:
2142 case QETH_CARD_TYPE_OSX
:
2143 case QETH_CARD_TYPE_IQD
:
2144 return ((mtu
>= 576) &&
2145 (mtu
<= card
->info
.max_mtu
));
2146 case QETH_CARD_TYPE_OSN
:
2147 case QETH_CARD_TYPE_UNKNOWN
:
2153 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2157 __u16 mtu
, framesize
;
2160 struct qeth_cmd_buffer
*iob
;
2162 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
2164 iob
= (struct qeth_cmd_buffer
*) data
;
2165 memcpy(&card
->token
.ulp_filter_r
,
2166 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2167 QETH_MPC_TOKEN_LENGTH
);
2168 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2169 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
2170 mtu
= qeth_get_mtu_outof_framesize(framesize
);
2173 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2176 if (card
->info
.initial_mtu
&& (card
->info
.initial_mtu
!= mtu
)) {
2177 /* frame size has changed */
2179 ((card
->dev
->mtu
== card
->info
.initial_mtu
) ||
2180 (card
->dev
->mtu
> mtu
)))
2181 card
->dev
->mtu
= mtu
;
2182 qeth_free_qdio_buffers(card
);
2184 card
->info
.initial_mtu
= mtu
;
2185 card
->info
.max_mtu
= mtu
;
2186 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
2188 card
->info
.initial_mtu
= qeth_get_initial_mtu_for_card(card
);
2189 card
->info
.max_mtu
= *(__u16
*)QETH_ULP_ENABLE_RESP_MAX_MTU(
2191 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
2194 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
2195 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
2197 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
2198 card
->info
.link_type
= link_type
;
2200 card
->info
.link_type
= 0;
2201 QETH_DBF_TEXT_(SETUP
, 2, "link%d", card
->info
.link_type
);
2202 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2206 static int qeth_ulp_enable(struct qeth_card
*card
)
2210 struct qeth_cmd_buffer
*iob
;
2212 /*FIXME: trace view callbacks*/
2213 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
2215 iob
= qeth_wait_for_buffer(&card
->write
);
2216 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
2218 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
2219 (__u8
) card
->info
.portno
;
2220 if (card
->options
.layer2
)
2221 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2222 prot_type
= QETH_PROT_OSN2
;
2224 prot_type
= QETH_PROT_LAYER2
;
2226 prot_type
= QETH_PROT_TCPIP
;
2228 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
2229 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
2230 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2231 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
2232 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2233 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob
->data
),
2234 card
->info
.portname
, 9);
2235 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
2236 qeth_ulp_enable_cb
, NULL
);
2241 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2244 struct qeth_cmd_buffer
*iob
;
2247 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
2249 iob
= (struct qeth_cmd_buffer
*) data
;
2250 memcpy(&card
->token
.ulp_connection_r
,
2251 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2252 QETH_MPC_TOKEN_LENGTH
);
2253 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2255 QETH_DBF_TEXT(SETUP
, 2, "olmlimit");
2256 dev_err(&card
->gdev
->dev
, "A connection could not be "
2257 "established because of an OLM limit\n");
2260 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2264 static int qeth_ulp_setup(struct qeth_card
*card
)
2268 struct qeth_cmd_buffer
*iob
;
2269 struct ccw_dev_id dev_id
;
2271 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2273 iob
= qeth_wait_for_buffer(&card
->write
);
2274 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2276 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2277 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2278 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2279 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2280 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2281 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2283 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2284 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2285 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2286 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2287 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2288 qeth_ulp_setup_cb
, NULL
);
2292 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*q
, int bidx
)
2295 struct qeth_qdio_out_buffer
*newbuf
;
2298 newbuf
= kmem_cache_zalloc(qeth_qdio_outbuf_cache
, GFP_ATOMIC
);
2303 newbuf
->buffer
= &q
->qdio_bufs
[bidx
];
2304 skb_queue_head_init(&newbuf
->skb_list
);
2305 lockdep_set_class(&newbuf
->skb_list
.lock
, &qdio_out_skb_queue_key
);
2308 newbuf
->next_pending
= q
->bufs
[bidx
];
2309 atomic_set(&newbuf
->state
, QETH_QDIO_BUF_EMPTY
);
2310 q
->bufs
[bidx
] = newbuf
;
2312 q
->bufstates
[bidx
].user
= newbuf
;
2313 QETH_CARD_TEXT_(q
->card
, 2, "nbs%d", bidx
);
2314 QETH_CARD_TEXT_(q
->card
, 2, "%lx", (long) newbuf
);
2315 QETH_CARD_TEXT_(q
->card
, 2, "%lx",
2316 (long) newbuf
->next_pending
);
2323 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2327 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2329 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2330 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2333 card
->qdio
.in_q
= kzalloc(sizeof(struct qeth_qdio_q
),
2335 if (!card
->qdio
.in_q
)
2337 QETH_DBF_TEXT(SETUP
, 2, "inq");
2338 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.in_q
, sizeof(void *));
2339 memset(card
->qdio
.in_q
, 0, sizeof(struct qeth_qdio_q
));
2340 /* give inbound qeth_qdio_buffers their qdio_buffers */
2341 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
2342 card
->qdio
.in_q
->bufs
[i
].buffer
=
2343 &card
->qdio
.in_q
->qdio_bufs
[i
];
2344 card
->qdio
.in_q
->bufs
[i
].rx_skb
= NULL
;
2346 /* inbound buffer pool */
2347 if (qeth_alloc_buffer_pool(card
))
2352 kzalloc(card
->qdio
.no_out_queues
*
2353 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2354 if (!card
->qdio
.out_qs
)
2356 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2357 card
->qdio
.out_qs
[i
] = kzalloc(sizeof(struct qeth_qdio_out_q
),
2359 if (!card
->qdio
.out_qs
[i
])
2361 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2362 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2363 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2364 /* give outbound qeth_qdio_buffers their qdio_buffers */
2365 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2366 BUG_ON(card
->qdio
.out_qs
[i
]->bufs
[j
] != NULL
);
2367 if (qeth_init_qdio_out_buf(card
->qdio
.out_qs
[i
], j
))
2368 goto out_freeoutqbufs
;
2373 if (qeth_alloc_cq(card
))
2381 kmem_cache_free(qeth_qdio_outbuf_cache
,
2382 card
->qdio
.out_qs
[i
]->bufs
[j
]);
2383 card
->qdio
.out_qs
[i
]->bufs
[j
] = NULL
;
2387 kfree(card
->qdio
.out_qs
[--i
]);
2388 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2390 kfree(card
->qdio
.out_qs
);
2391 card
->qdio
.out_qs
= NULL
;
2393 qeth_free_buffer_pool(card
);
2395 kfree(card
->qdio
.in_q
);
2396 card
->qdio
.in_q
= NULL
;
2398 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2402 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2406 param_field
[0] = _ascebc
['P'];
2407 param_field
[1] = _ascebc
['C'];
2408 param_field
[2] = _ascebc
['I'];
2409 param_field
[3] = _ascebc
['T'];
2410 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2411 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2412 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2415 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2418 param_field
[16] = _ascebc
['B'];
2419 param_field
[17] = _ascebc
['L'];
2420 param_field
[18] = _ascebc
['K'];
2421 param_field
[19] = _ascebc
['T'];
2422 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2423 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2424 *((unsigned int *) (¶m_field
[28])) =
2425 card
->info
.blkt
.inter_packet_jumbo
;
2428 static int qeth_qdio_activate(struct qeth_card
*card
)
2430 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2431 return qdio_activate(CARD_DDEV(card
));
2434 static int qeth_dm_act(struct qeth_card
*card
)
2437 struct qeth_cmd_buffer
*iob
;
2439 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2441 iob
= qeth_wait_for_buffer(&card
->write
);
2442 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2444 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2445 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2446 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2447 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2448 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2452 static int qeth_mpc_initialize(struct qeth_card
*card
)
2456 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2458 rc
= qeth_issue_next_read(card
);
2460 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2463 rc
= qeth_cm_enable(card
);
2465 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2468 rc
= qeth_cm_setup(card
);
2470 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2473 rc
= qeth_ulp_enable(card
);
2475 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2478 rc
= qeth_ulp_setup(card
);
2480 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2483 rc
= qeth_alloc_qdio_buffers(card
);
2485 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2488 rc
= qeth_qdio_establish(card
);
2490 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2491 qeth_free_qdio_buffers(card
);
2494 rc
= qeth_qdio_activate(card
);
2496 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2499 rc
= qeth_dm_act(card
);
2501 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2507 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2511 static void qeth_print_status_with_portname(struct qeth_card
*card
)
2516 sprintf(dbf_text
, "%s", card
->info
.portname
+ 1);
2517 for (i
= 0; i
< 8; i
++)
2519 (char) _ebcasc
[(__u8
) dbf_text
[i
]];
2521 dev_info(&card
->gdev
->dev
, "Device is a%s card%s%s%s\n"
2522 "with link type %s (portname: %s)\n",
2523 qeth_get_cardname(card
),
2524 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2525 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2526 (card
->info
.mcl_level
[0]) ? ")" : "",
2527 qeth_get_cardname_short(card
),
2532 static void qeth_print_status_no_portname(struct qeth_card
*card
)
2534 if (card
->info
.portname
[0])
2535 dev_info(&card
->gdev
->dev
, "Device is a%s "
2536 "card%s%s%s\nwith link type %s "
2537 "(no portname needed by interface).\n",
2538 qeth_get_cardname(card
),
2539 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2540 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2541 (card
->info
.mcl_level
[0]) ? ")" : "",
2542 qeth_get_cardname_short(card
));
2544 dev_info(&card
->gdev
->dev
, "Device is a%s "
2545 "card%s%s%s\nwith link type %s.\n",
2546 qeth_get_cardname(card
),
2547 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2548 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2549 (card
->info
.mcl_level
[0]) ? ")" : "",
2550 qeth_get_cardname_short(card
));
2553 void qeth_print_status_message(struct qeth_card
*card
)
2555 switch (card
->info
.type
) {
2556 case QETH_CARD_TYPE_OSD
:
2557 case QETH_CARD_TYPE_OSM
:
2558 case QETH_CARD_TYPE_OSX
:
2559 /* VM will use a non-zero first character
2560 * to indicate a HiperSockets like reporting
2561 * of the level OSA sets the first character to zero
2563 if (!card
->info
.mcl_level
[0]) {
2564 sprintf(card
->info
.mcl_level
, "%02x%02x",
2565 card
->info
.mcl_level
[2],
2566 card
->info
.mcl_level
[3]);
2568 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2572 case QETH_CARD_TYPE_IQD
:
2573 if ((card
->info
.guestlan
) ||
2574 (card
->info
.mcl_level
[0] & 0x80)) {
2575 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2576 card
->info
.mcl_level
[0]];
2577 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2578 card
->info
.mcl_level
[1]];
2579 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2580 card
->info
.mcl_level
[2]];
2581 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2582 card
->info
.mcl_level
[3]];
2583 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2587 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2589 if (card
->info
.portname_required
)
2590 qeth_print_status_with_portname(card
);
2592 qeth_print_status_no_portname(card
);
2594 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2596 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2598 struct qeth_buffer_pool_entry
*entry
;
2600 QETH_CARD_TEXT(card
, 5, "inwrklst");
2602 list_for_each_entry(entry
,
2603 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2604 qeth_put_buffer_pool_entry(card
, entry
);
2608 static inline struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2609 struct qeth_card
*card
)
2611 struct list_head
*plh
;
2612 struct qeth_buffer_pool_entry
*entry
;
2616 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2619 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2620 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2622 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2623 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2629 list_del_init(&entry
->list
);
2634 /* no free buffer in pool so take first one and swap pages */
2635 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2636 struct qeth_buffer_pool_entry
, list
);
2637 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2638 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2639 page
= alloc_page(GFP_ATOMIC
);
2643 free_page((unsigned long)entry
->elements
[i
]);
2644 entry
->elements
[i
] = page_address(page
);
2645 if (card
->options
.performance_stats
)
2646 card
->perf_stats
.sg_alloc_page_rx
++;
2650 list_del_init(&entry
->list
);
2654 static int qeth_init_input_buffer(struct qeth_card
*card
,
2655 struct qeth_qdio_buffer
*buf
)
2657 struct qeth_buffer_pool_entry
*pool_entry
;
2660 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && (!buf
->rx_skb
)) {
2661 buf
->rx_skb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
2666 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2671 * since the buffer is accessed only from the input_tasklet
2672 * there shouldn't be a need to synchronize; also, since we use
2673 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2677 buf
->pool_entry
= pool_entry
;
2678 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2679 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2680 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2681 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2682 buf
->buffer
->element
[i
].eflags
= SBAL_EFLAGS_LAST_ENTRY
;
2684 buf
->buffer
->element
[i
].eflags
= 0;
2685 buf
->buffer
->element
[i
].sflags
= 0;
2690 int qeth_init_qdio_queues(struct qeth_card
*card
)
2695 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2698 memset(card
->qdio
.in_q
->qdio_bufs
, 0,
2699 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2700 qeth_initialize_working_pool_list(card
);
2701 /*give only as many buffers to hardware as we have buffer pool entries*/
2702 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2703 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2704 card
->qdio
.in_q
->next_buf_to_init
=
2705 card
->qdio
.in_buf_pool
.buf_count
- 1;
2706 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2707 card
->qdio
.in_buf_pool
.buf_count
- 1);
2709 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2714 rc
= qeth_cq_init(card
);
2719 /* outbound queue */
2720 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2721 memset(card
->qdio
.out_qs
[i
]->qdio_bufs
, 0,
2722 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2723 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2724 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2725 card
->qdio
.out_qs
[i
]->bufs
[j
],
2726 QETH_QDIO_BUF_EMPTY
);
2728 card
->qdio
.out_qs
[i
]->card
= card
;
2729 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2730 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2731 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2732 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2733 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2734 QETH_OUT_Q_UNLOCKED
);
2738 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2740 static inline __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2742 switch (link_type
) {
2743 case QETH_LINK_TYPE_HSTR
:
2750 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2751 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2752 enum qeth_prot_versions prot
)
2754 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2755 cmd
->hdr
.command
= command
;
2756 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2757 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2758 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2759 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2760 if (card
->options
.layer2
)
2761 cmd
->hdr
.prim_version_no
= 2;
2763 cmd
->hdr
.prim_version_no
= 1;
2764 cmd
->hdr
.param_count
= 1;
2765 cmd
->hdr
.prot_version
= prot
;
2766 cmd
->hdr
.ipa_supported
= 0;
2767 cmd
->hdr
.ipa_enabled
= 0;
2770 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2771 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2773 struct qeth_cmd_buffer
*iob
;
2774 struct qeth_ipa_cmd
*cmd
;
2776 iob
= qeth_wait_for_buffer(&card
->write
);
2777 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2778 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2782 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2784 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2787 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2788 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2789 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2790 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2792 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2794 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2795 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2802 QETH_CARD_TEXT(card
, 4, "sendipa");
2804 if (card
->options
.layer2
)
2805 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2806 prot_type
= QETH_PROT_OSN2
;
2808 prot_type
= QETH_PROT_LAYER2
;
2810 prot_type
= QETH_PROT_TCPIP
;
2811 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
2812 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
2813 iob
, reply_cb
, reply_param
);
2815 qeth_clear_ipacmd_list(card
);
2816 qeth_schedule_recovery(card
);
2820 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
2822 int qeth_send_startlan(struct qeth_card
*card
)
2825 struct qeth_cmd_buffer
*iob
;
2827 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
2829 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_STARTLAN
, 0);
2830 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
2833 EXPORT_SYMBOL_GPL(qeth_send_startlan
);
2835 int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
2836 struct qeth_reply
*reply
, unsigned long data
)
2838 struct qeth_ipa_cmd
*cmd
;
2840 QETH_CARD_TEXT(card
, 4, "defadpcb");
2842 cmd
= (struct qeth_ipa_cmd
*) data
;
2843 if (cmd
->hdr
.return_code
== 0)
2844 cmd
->hdr
.return_code
=
2845 cmd
->data
.setadapterparms
.hdr
.return_code
;
2848 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb
);
2850 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
2851 struct qeth_reply
*reply
, unsigned long data
)
2853 struct qeth_ipa_cmd
*cmd
;
2855 QETH_CARD_TEXT(card
, 3, "quyadpcb");
2857 cmd
= (struct qeth_ipa_cmd
*) data
;
2858 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f) {
2859 card
->info
.link_type
=
2860 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
2861 QETH_DBF_TEXT_(SETUP
, 2, "lnk %d", card
->info
.link_type
);
2863 card
->options
.adp
.supported_funcs
=
2864 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
2865 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
2868 struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
2869 __u32 command
, __u32 cmdlen
)
2871 struct qeth_cmd_buffer
*iob
;
2872 struct qeth_ipa_cmd
*cmd
;
2874 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
2876 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2877 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
2878 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
2879 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
2880 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
2884 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd
);
2886 int qeth_query_setadapterparms(struct qeth_card
*card
)
2889 struct qeth_cmd_buffer
*iob
;
2891 QETH_CARD_TEXT(card
, 3, "queryadp");
2892 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
2893 sizeof(struct qeth_ipacmd_setadpparms
));
2894 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
2897 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
2899 static int qeth_query_ipassists_cb(struct qeth_card
*card
,
2900 struct qeth_reply
*reply
, unsigned long data
)
2902 struct qeth_ipa_cmd
*cmd
;
2904 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
2906 cmd
= (struct qeth_ipa_cmd
*) data
;
2907 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
2908 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
2909 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
2911 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
2912 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
2914 QETH_DBF_TEXT(SETUP
, 2, "suppenbl");
2915 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_supported
);
2916 QETH_DBF_TEXT_(SETUP
, 2, "%x", cmd
->hdr
.ipa_enabled
);
2920 int qeth_query_ipassists(struct qeth_card
*card
, enum qeth_prot_versions prot
)
2923 struct qeth_cmd_buffer
*iob
;
2925 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
2926 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
2927 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_ipassists_cb
, NULL
);
2930 EXPORT_SYMBOL_GPL(qeth_query_ipassists
);
2932 static int qeth_query_setdiagass_cb(struct qeth_card
*card
,
2933 struct qeth_reply
*reply
, unsigned long data
)
2935 struct qeth_ipa_cmd
*cmd
;
2938 cmd
= (struct qeth_ipa_cmd
*)data
;
2939 rc
= cmd
->hdr
.return_code
;
2941 QETH_CARD_TEXT_(card
, 2, "diagq:%x", rc
);
2943 card
->info
.diagass_support
= cmd
->data
.diagass
.ext
;
2947 static int qeth_query_setdiagass(struct qeth_card
*card
)
2949 struct qeth_cmd_buffer
*iob
;
2950 struct qeth_ipa_cmd
*cmd
;
2952 QETH_DBF_TEXT(SETUP
, 2, "qdiagass");
2953 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
2954 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2955 cmd
->data
.diagass
.subcmd_len
= 16;
2956 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_QUERY
;
2957 return qeth_send_ipa_cmd(card
, iob
, qeth_query_setdiagass_cb
, NULL
);
2960 static void qeth_get_trap_id(struct qeth_card
*card
, struct qeth_trap_id
*tid
)
2962 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
2963 struct sysinfo_2_2_2
*info222
= (struct sysinfo_2_2_2
*)info
;
2964 struct sysinfo_3_2_2
*info322
= (struct sysinfo_3_2_2
*)info
;
2965 struct ccw_dev_id ccwid
;
2968 tid
->chpid
= card
->info
.chpid
;
2969 ccw_device_get_id(CARD_RDEV(card
), &ccwid
);
2970 tid
->ssid
= ccwid
.ssid
;
2971 tid
->devno
= ccwid
.devno
;
2975 rc
= stsi(NULL
, 0, 0, 0);
2979 level
= (((unsigned int) rc
) >> 28);
2981 if ((level
>= 2) && (stsi(info222
, 2, 2, 2) != -ENOSYS
))
2982 tid
->lparnr
= info222
->lpar_number
;
2984 if ((level
>= 3) && (stsi(info322
, 3, 2, 2) != -ENOSYS
)) {
2985 EBCASC(info322
->vm
[0].name
, sizeof(info322
->vm
[0].name
));
2986 memcpy(tid
->vmname
, info322
->vm
[0].name
, sizeof(tid
->vmname
));
2992 static int qeth_hw_trap_cb(struct qeth_card
*card
,
2993 struct qeth_reply
*reply
, unsigned long data
)
2995 struct qeth_ipa_cmd
*cmd
;
2998 cmd
= (struct qeth_ipa_cmd
*)data
;
2999 rc
= cmd
->hdr
.return_code
;
3001 QETH_CARD_TEXT_(card
, 2, "trapc:%x", rc
);
3005 int qeth_hw_trap(struct qeth_card
*card
, enum qeth_diags_trap_action action
)
3007 struct qeth_cmd_buffer
*iob
;
3008 struct qeth_ipa_cmd
*cmd
;
3010 QETH_DBF_TEXT(SETUP
, 2, "diagtrap");
3011 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3012 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3013 cmd
->data
.diagass
.subcmd_len
= 80;
3014 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRAP
;
3015 cmd
->data
.diagass
.type
= 1;
3016 cmd
->data
.diagass
.action
= action
;
3018 case QETH_DIAGS_TRAP_ARM
:
3019 cmd
->data
.diagass
.options
= 0x0003;
3020 cmd
->data
.diagass
.ext
= 0x00010000 +
3021 sizeof(struct qeth_trap_id
);
3022 qeth_get_trap_id(card
,
3023 (struct qeth_trap_id
*)cmd
->data
.diagass
.cdata
);
3025 case QETH_DIAGS_TRAP_DISARM
:
3026 cmd
->data
.diagass
.options
= 0x0001;
3028 case QETH_DIAGS_TRAP_CAPTURE
:
3031 return qeth_send_ipa_cmd(card
, iob
, qeth_hw_trap_cb
, NULL
);
3033 EXPORT_SYMBOL_GPL(qeth_hw_trap
);
3035 int qeth_check_qdio_errors(struct qeth_card
*card
, struct qdio_buffer
*buf
,
3036 unsigned int qdio_error
, const char *dbftext
)
3039 QETH_CARD_TEXT(card
, 2, dbftext
);
3040 QETH_CARD_TEXT_(card
, 2, " F15=%02X",
3041 buf
->element
[15].sflags
);
3042 QETH_CARD_TEXT_(card
, 2, " F14=%02X",
3043 buf
->element
[14].sflags
);
3044 QETH_CARD_TEXT_(card
, 2, " qerr=%X", qdio_error
);
3045 if ((buf
->element
[15].sflags
) == 0x12) {
3046 card
->stats
.rx_dropped
++;
3053 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors
);
3055 void qeth_buffer_reclaim_work(struct work_struct
*work
)
3057 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
3058 buffer_reclaim_work
.work
);
3060 QETH_CARD_TEXT_(card
, 2, "brw:%x", card
->reclaim_index
);
3061 qeth_queue_input_buffer(card
, card
->reclaim_index
);
3064 void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
3066 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
3067 struct list_head
*lh
;
3073 count
= (index
< queue
->next_buf_to_init
)?
3074 card
->qdio
.in_buf_pool
.buf_count
-
3075 (queue
->next_buf_to_init
- index
) :
3076 card
->qdio
.in_buf_pool
.buf_count
-
3077 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
3078 /* only requeue at a certain threshold to avoid SIGAs */
3079 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
3080 for (i
= queue
->next_buf_to_init
;
3081 i
< queue
->next_buf_to_init
+ count
; ++i
) {
3082 if (qeth_init_input_buffer(card
,
3083 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
3090 if (newcount
< count
) {
3091 /* we are in memory shortage so we switch back to
3092 traditional skb allocation and drop packages */
3093 atomic_set(&card
->force_alloc_skb
, 3);
3096 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
3101 list_for_each(lh
, &card
->qdio
.in_buf_pool
.entry_list
)
3103 if (i
== card
->qdio
.in_buf_pool
.buf_count
) {
3104 QETH_CARD_TEXT(card
, 2, "qsarbw");
3105 card
->reclaim_index
= index
;
3106 schedule_delayed_work(
3107 &card
->buffer_reclaim_work
,
3108 QETH_RECLAIM_WORK_TIME
);
3114 * according to old code it should be avoided to requeue all
3115 * 128 buffers in order to benefit from PCI avoidance.
3116 * this function keeps at least one buffer (the buffer at
3117 * 'index') un-requeued -> this buffer is the first buffer that
3118 * will be requeued the next time
3120 if (card
->options
.performance_stats
) {
3121 card
->perf_stats
.inbound_do_qdio_cnt
++;
3122 card
->perf_stats
.inbound_do_qdio_start_time
=
3125 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
3126 queue
->next_buf_to_init
, count
);
3127 if (card
->options
.performance_stats
)
3128 card
->perf_stats
.inbound_do_qdio_time
+=
3130 card
->perf_stats
.inbound_do_qdio_start_time
;
3132 QETH_CARD_TEXT(card
, 2, "qinberr");
3134 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
3135 QDIO_MAX_BUFFERS_PER_Q
;
3138 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer
);
3140 static int qeth_handle_send_error(struct qeth_card
*card
,
3141 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
3143 int sbalf15
= buffer
->buffer
->element
[15].sflags
;
3145 QETH_CARD_TEXT(card
, 6, "hdsnderr");
3146 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3153 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
3156 return QETH_SEND_ERROR_NONE
;
3158 if ((sbalf15
>= 15) && (sbalf15
<= 31))
3159 return QETH_SEND_ERROR_RETRY
;
3161 QETH_CARD_TEXT(card
, 1, "lnkfail");
3162 QETH_CARD_TEXT_(card
, 1, "%04x %02x",
3163 (u16
)qdio_err
, (u8
)sbalf15
);
3164 return QETH_SEND_ERROR_LINK_FAILURE
;
3168 * Switched to packing state if the number of used buffers on a queue
3169 * reaches a certain limit.
3171 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
3173 if (!queue
->do_pack
) {
3174 if (atomic_read(&queue
->used_buffers
)
3175 >= QETH_HIGH_WATERMARK_PACK
){
3176 /* switch non-PACKING -> PACKING */
3177 QETH_CARD_TEXT(queue
->card
, 6, "np->pack");
3178 if (queue
->card
->options
.performance_stats
)
3179 queue
->card
->perf_stats
.sc_dp_p
++;
3186 * Switches from packing to non-packing mode. If there is a packing
3187 * buffer on the queue this buffer will be prepared to be flushed.
3188 * In that case 1 is returned to inform the caller. If no buffer
3189 * has to be flushed, zero is returned.
3191 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
3193 struct qeth_qdio_out_buffer
*buffer
;
3194 int flush_count
= 0;
3196 if (queue
->do_pack
) {
3197 if (atomic_read(&queue
->used_buffers
)
3198 <= QETH_LOW_WATERMARK_PACK
) {
3199 /* switch PACKING -> non-PACKING */
3200 QETH_CARD_TEXT(queue
->card
, 6, "pack->np");
3201 if (queue
->card
->options
.performance_stats
)
3202 queue
->card
->perf_stats
.sc_p_dp
++;
3204 /* flush packing buffers */
3205 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3206 if ((atomic_read(&buffer
->state
) ==
3207 QETH_QDIO_BUF_EMPTY
) &&
3208 (buffer
->next_element_to_fill
> 0)) {
3209 atomic_set(&buffer
->state
,
3210 QETH_QDIO_BUF_PRIMED
);
3212 queue
->next_buf_to_fill
=
3213 (queue
->next_buf_to_fill
+ 1) %
3214 QDIO_MAX_BUFFERS_PER_Q
;
3223 * Called to flush a packing buffer if no more pci flags are on the queue.
3224 * Checks if there is a packing buffer and prepares it to be flushed.
3225 * In that case returns 1, otherwise zero.
3227 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q
*queue
)
3229 struct qeth_qdio_out_buffer
*buffer
;
3231 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3232 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
3233 (buffer
->next_element_to_fill
> 0)) {
3234 /* it's a packing buffer */
3235 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3236 queue
->next_buf_to_fill
=
3237 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
3243 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
3246 struct qeth_qdio_out_buffer
*buf
;
3249 unsigned int qdio_flags
;
3251 for (i
= index
; i
< index
+ count
; ++i
) {
3252 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3253 buf
= queue
->bufs
[bidx
];
3254 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].eflags
|=
3255 SBAL_EFLAGS_LAST_ENTRY
;
3257 if (queue
->bufstates
)
3258 queue
->bufstates
[bidx
].user
= buf
;
3260 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
3263 if (!queue
->do_pack
) {
3264 if ((atomic_read(&queue
->used_buffers
) >=
3265 (QETH_HIGH_WATERMARK_PACK
-
3266 QETH_WATERMARK_PACK_FUZZ
)) &&
3267 !atomic_read(&queue
->set_pci_flags_count
)) {
3268 /* it's likely that we'll go to packing
3270 atomic_inc(&queue
->set_pci_flags_count
);
3271 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3274 if (!atomic_read(&queue
->set_pci_flags_count
)) {
3276 * there's no outstanding PCI any more, so we
3277 * have to request a PCI to be sure the the PCI
3278 * will wake at some time in the future then we
3279 * can flush packed buffers that might still be
3280 * hanging around, which can happen if no
3281 * further send was requested by the stack
3283 atomic_inc(&queue
->set_pci_flags_count
);
3284 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3289 queue
->card
->dev
->trans_start
= jiffies
;
3290 if (queue
->card
->options
.performance_stats
) {
3291 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
3292 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
3295 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
3296 if (atomic_read(&queue
->set_pci_flags_count
))
3297 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
3298 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
3299 queue
->queue_no
, index
, count
);
3300 if (queue
->card
->options
.performance_stats
)
3301 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
3303 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
3304 atomic_add(count
, &queue
->used_buffers
);
3306 queue
->card
->stats
.tx_errors
+= count
;
3307 /* ignore temporary SIGA errors without busy condition */
3308 if (rc
== QDIO_ERROR_SIGA_TARGET
)
3310 QETH_CARD_TEXT(queue
->card
, 2, "flushbuf");
3311 QETH_CARD_TEXT_(queue
->card
, 2, " q%d", queue
->queue_no
);
3312 QETH_CARD_TEXT_(queue
->card
, 2, " idx%d", index
);
3313 QETH_CARD_TEXT_(queue
->card
, 2, " c%d", count
);
3314 QETH_CARD_TEXT_(queue
->card
, 2, " err%d", rc
);
3316 /* this must not happen under normal circumstances. if it
3317 * happens something is really wrong -> recover */
3318 qeth_schedule_recovery(queue
->card
);
3321 if (queue
->card
->options
.performance_stats
)
3322 queue
->card
->perf_stats
.bufs_sent
+= count
;
3325 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
3329 int q_was_packing
= 0;
3332 * check if weed have to switch to non-packing mode or if
3333 * we have to get a pci flag out on the queue
3335 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
3336 !atomic_read(&queue
->set_pci_flags_count
)) {
3337 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
3338 QETH_OUT_Q_UNLOCKED
) {
3340 * If we get in here, there was no action in
3341 * do_send_packet. So, we check if there is a
3342 * packing buffer to be flushed here.
3344 netif_stop_queue(queue
->card
->dev
);
3345 index
= queue
->next_buf_to_fill
;
3346 q_was_packing
= queue
->do_pack
;
3347 /* queue->do_pack may change */
3349 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
3351 !atomic_read(&queue
->set_pci_flags_count
))
3353 qeth_flush_buffers_on_no_pci(queue
);
3354 if (queue
->card
->options
.performance_stats
&&
3356 queue
->card
->perf_stats
.bufs_sent_pack
+=
3359 qeth_flush_buffers(queue
, index
, flush_cnt
);
3360 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3365 void qeth_qdio_start_poll(struct ccw_device
*ccwdev
, int queue
,
3366 unsigned long card_ptr
)
3368 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3370 if (card
->dev
&& (card
->dev
->flags
& IFF_UP
))
3371 napi_schedule(&card
->napi
);
3373 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll
);
3375 int qeth_configure_cq(struct qeth_card
*card
, enum qeth_cq cq
)
3379 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
) {
3383 if (card
->options
.cq
== cq
) {
3388 if (card
->state
!= CARD_STATE_DOWN
&&
3389 card
->state
!= CARD_STATE_RECOVER
) {
3394 qeth_free_qdio_buffers(card
);
3395 card
->options
.cq
= cq
;
3402 EXPORT_SYMBOL_GPL(qeth_configure_cq
);
3405 static void qeth_qdio_cq_handler(struct qeth_card
*card
,
3406 unsigned int qdio_err
,
3407 unsigned int queue
, int first_element
, int count
) {
3408 struct qeth_qdio_q
*cq
= card
->qdio
.c_q
;
3412 if (!qeth_is_cq(card
, queue
))
3415 QETH_CARD_TEXT_(card
, 5, "qcqhe%d", first_element
);
3416 QETH_CARD_TEXT_(card
, 5, "qcqhc%d", count
);
3417 QETH_CARD_TEXT_(card
, 5, "qcqherr%d", qdio_err
);
3420 netif_stop_queue(card
->dev
);
3421 qeth_schedule_recovery(card
);
3425 if (card
->options
.performance_stats
) {
3426 card
->perf_stats
.cq_cnt
++;
3427 card
->perf_stats
.cq_start_time
= qeth_get_micros();
3430 for (i
= first_element
; i
< first_element
+ count
; ++i
) {
3431 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3432 struct qdio_buffer
*buffer
= &cq
->qdio_bufs
[bidx
];
3436 while (buffer
->element
[e
].addr
) {
3437 unsigned long phys_aob_addr
;
3439 phys_aob_addr
= (unsigned long) buffer
->element
[e
].addr
;
3440 qeth_qdio_handle_aob(card
, phys_aob_addr
);
3441 buffer
->element
[e
].addr
= NULL
;
3442 buffer
->element
[e
].eflags
= 0;
3443 buffer
->element
[e
].sflags
= 0;
3444 buffer
->element
[e
].length
= 0;
3449 buffer
->element
[15].eflags
= 0;
3450 buffer
->element
[15].sflags
= 0;
3452 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, queue
,
3453 card
->qdio
.c_q
->next_buf_to_init
,
3456 dev_warn(&card
->gdev
->dev
,
3457 "QDIO reported an error, rc=%i\n", rc
);
3458 QETH_CARD_TEXT(card
, 2, "qcqherr");
3460 card
->qdio
.c_q
->next_buf_to_init
= (card
->qdio
.c_q
->next_buf_to_init
3461 + count
) % QDIO_MAX_BUFFERS_PER_Q
;
3463 netif_wake_queue(card
->dev
);
3465 if (card
->options
.performance_stats
) {
3466 int delta_t
= qeth_get_micros();
3467 delta_t
-= card
->perf_stats
.cq_start_time
;
3468 card
->perf_stats
.cq_time
+= delta_t
;
3474 void qeth_qdio_input_handler(struct ccw_device
*ccwdev
, unsigned int qdio_err
,
3475 unsigned int queue
, int first_elem
, int count
,
3476 unsigned long card_ptr
)
3478 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3480 QETH_CARD_TEXT_(card
, 2, "qihq%d", queue
);
3481 QETH_CARD_TEXT_(card
, 2, "qiec%d", qdio_err
);
3483 if (qeth_is_cq(card
, queue
))
3484 qeth_qdio_cq_handler(card
, qdio_err
, queue
, first_elem
, count
);
3486 qeth_schedule_recovery(card
);
3490 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler
);
3492 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
3493 unsigned int qdio_error
, int __queue
, int first_element
,
3494 int count
, unsigned long card_ptr
)
3496 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
3497 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
3498 struct qeth_qdio_out_buffer
*buffer
;
3501 QETH_CARD_TEXT(card
, 6, "qdouhdl");
3502 if (qdio_error
& QDIO_ERROR_ACTIVATE_CHECK_CONDITION
) {
3503 QETH_CARD_TEXT(card
, 2, "achkcond");
3504 netif_stop_queue(card
->dev
);
3505 qeth_schedule_recovery(card
);
3508 if (card
->options
.performance_stats
) {
3509 card
->perf_stats
.outbound_handler_cnt
++;
3510 card
->perf_stats
.outbound_handler_start_time
=
3513 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3514 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3515 buffer
= queue
->bufs
[bidx
];
3516 qeth_handle_send_error(card
, buffer
, qdio_error
);
3518 if (queue
->bufstates
&&
3519 (queue
->bufstates
[bidx
].flags
&
3520 QDIO_OUTBUF_STATE_FLAG_PENDING
) != 0) {
3521 BUG_ON(card
->options
.cq
!= QETH_CQ_ENABLED
);
3523 if (atomic_cmpxchg(&buffer
->state
,
3524 QETH_QDIO_BUF_PRIMED
,
3525 QETH_QDIO_BUF_PENDING
) ==
3526 QETH_QDIO_BUF_PRIMED
) {
3527 qeth_notify_skbs(queue
, buffer
,
3530 buffer
->aob
= queue
->bufstates
[bidx
].aob
;
3531 QETH_CARD_TEXT_(queue
->card
, 5, "pel%d", bidx
);
3532 QETH_CARD_TEXT(queue
->card
, 5, "aob");
3533 QETH_CARD_TEXT_(queue
->card
, 5, "%lx",
3534 virt_to_phys(buffer
->aob
));
3535 BUG_ON(bidx
< 0 || bidx
>= QDIO_MAX_BUFFERS_PER_Q
);
3536 if (qeth_init_qdio_out_buf(queue
, bidx
)) {
3537 QETH_CARD_TEXT(card
, 2, "outofbuf");
3538 qeth_schedule_recovery(card
);
3541 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
3542 enum iucv_tx_notify n
;
3544 n
= qeth_compute_cq_notification(
3545 buffer
->buffer
->element
[15].sflags
, 0);
3546 qeth_notify_skbs(queue
, buffer
, n
);
3549 qeth_clear_output_buffer(queue
, buffer
,
3550 QETH_QDIO_BUF_EMPTY
);
3552 qeth_cleanup_handled_pending(queue
, bidx
, 0);
3554 atomic_sub(count
, &queue
->used_buffers
);
3555 /* check if we need to do something on this outbound queue */
3556 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3557 qeth_check_outbound_queue(queue
);
3559 netif_wake_queue(queue
->card
->dev
);
3560 if (card
->options
.performance_stats
)
3561 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
3562 card
->perf_stats
.outbound_handler_start_time
;
3564 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
3566 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
3567 int ipv
, int cast_type
)
3569 if (!ipv
&& (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3570 card
->info
.type
== QETH_CARD_TYPE_OSX
))
3571 return card
->qdio
.default_out_queue
;
3572 switch (card
->qdio
.no_out_queues
) {
3574 if (cast_type
&& card
->info
.is_multicast_different
)
3575 return card
->info
.is_multicast_different
&
3576 (card
->qdio
.no_out_queues
- 1);
3577 if (card
->qdio
.do_prio_queueing
&& (ipv
== 4)) {
3578 const u8 tos
= ip_hdr(skb
)->tos
;
3580 if (card
->qdio
.do_prio_queueing
==
3581 QETH_PRIO_Q_ING_TOS
) {
3582 if (tos
& IP_TOS_NOTIMPORTANT
)
3584 if (tos
& IP_TOS_HIGHRELIABILITY
)
3586 if (tos
& IP_TOS_HIGHTHROUGHPUT
)
3588 if (tos
& IP_TOS_LOWDELAY
)
3591 if (card
->qdio
.do_prio_queueing
==
3592 QETH_PRIO_Q_ING_PREC
)
3593 return 3 - (tos
>> 6);
3594 } else if (card
->qdio
.do_prio_queueing
&& (ipv
== 6)) {
3597 return card
->qdio
.default_out_queue
;
3598 case 1: /* fallthrough for single-out-queue 1920-device */
3600 return card
->qdio
.default_out_queue
;
3603 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
3605 int qeth_get_elements_no(struct qeth_card
*card
, void *hdr
,
3606 struct sk_buff
*skb
, int elems
)
3608 int dlen
= skb
->len
- skb
->data_len
;
3609 int elements_needed
= PFN_UP((unsigned long)skb
->data
+ dlen
- 1) -
3610 PFN_DOWN((unsigned long)skb
->data
);
3612 elements_needed
+= skb_shinfo(skb
)->nr_frags
;
3613 if ((elements_needed
+ elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3614 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3615 "(Number=%d / Length=%d). Discarded.\n",
3616 (elements_needed
+elems
), skb
->len
);
3619 return elements_needed
;
3621 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3623 int qeth_hdr_chk_and_bounce(struct sk_buff
*skb
, int len
)
3625 int hroom
, inpage
, rest
;
3627 if (((unsigned long)skb
->data
& PAGE_MASK
) !=
3628 (((unsigned long)skb
->data
+ len
- 1) & PAGE_MASK
)) {
3629 hroom
= skb_headroom(skb
);
3630 inpage
= PAGE_SIZE
- ((unsigned long) skb
->data
% PAGE_SIZE
);
3631 rest
= len
- inpage
;
3634 memmove(skb
->data
- rest
, skb
->data
, skb
->len
- skb
->data_len
);
3636 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len
, rest
);
3640 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce
);
3642 static inline void __qeth_fill_buffer(struct sk_buff
*skb
,
3643 struct qdio_buffer
*buffer
, int is_tso
, int *next_element_to_fill
,
3646 int length
= skb
->len
- skb
->data_len
;
3651 struct skb_frag_struct
*frag
;
3653 element
= *next_element_to_fill
;
3655 first_lap
= (is_tso
== 0 ? 1 : 0);
3658 data
= skb
->data
+ offset
;
3663 while (length
> 0) {
3664 /* length_here is the remaining amount of data in this page */
3665 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3666 if (length
< length_here
)
3667 length_here
= length
;
3669 buffer
->element
[element
].addr
= data
;
3670 buffer
->element
[element
].length
= length_here
;
3671 length
-= length_here
;
3674 if (skb_shinfo(skb
)->nr_frags
)
3675 buffer
->element
[element
].eflags
=
3676 SBAL_EFLAGS_FIRST_FRAG
;
3678 buffer
->element
[element
].eflags
= 0;
3680 buffer
->element
[element
].eflags
=
3681 SBAL_EFLAGS_MIDDLE_FRAG
;
3684 buffer
->element
[element
].eflags
=
3685 SBAL_EFLAGS_FIRST_FRAG
;
3687 buffer
->element
[element
].eflags
=
3688 SBAL_EFLAGS_MIDDLE_FRAG
;
3690 data
+= length_here
;
3695 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3696 frag
= &skb_shinfo(skb
)->frags
[cnt
];
3697 buffer
->element
[element
].addr
= (char *)page_to_phys(frag
->page
)
3698 + frag
->page_offset
;
3699 buffer
->element
[element
].length
= frag
->size
;
3700 buffer
->element
[element
].eflags
= SBAL_EFLAGS_MIDDLE_FRAG
;
3704 if (buffer
->element
[element
- 1].eflags
)
3705 buffer
->element
[element
- 1].eflags
= SBAL_EFLAGS_LAST_FRAG
;
3706 *next_element_to_fill
= element
;
3709 static inline int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
3710 struct qeth_qdio_out_buffer
*buf
, struct sk_buff
*skb
,
3711 struct qeth_hdr
*hdr
, int offset
, int hd_len
)
3713 struct qdio_buffer
*buffer
;
3714 int flush_cnt
= 0, hdr_len
, large_send
= 0;
3716 buffer
= buf
->buffer
;
3717 atomic_inc(&skb
->users
);
3718 skb_queue_tail(&buf
->skb_list
, skb
);
3720 /*check first on TSO ....*/
3721 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_TSO
) {
3722 int element
= buf
->next_element_to_fill
;
3724 hdr_len
= sizeof(struct qeth_hdr_tso
) +
3725 ((struct qeth_hdr_tso
*)hdr
)->ext
.dg_hdr_len
;
3726 /*fill first buffer entry only with header information */
3727 buffer
->element
[element
].addr
= skb
->data
;
3728 buffer
->element
[element
].length
= hdr_len
;
3729 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3730 buf
->next_element_to_fill
++;
3731 skb
->data
+= hdr_len
;
3732 skb
->len
-= hdr_len
;
3737 int element
= buf
->next_element_to_fill
;
3738 buffer
->element
[element
].addr
= hdr
;
3739 buffer
->element
[element
].length
= sizeof(struct qeth_hdr
) +
3741 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3742 buf
->is_header
[element
] = 1;
3743 buf
->next_element_to_fill
++;
3746 __qeth_fill_buffer(skb
, buffer
, large_send
,
3747 (int *)&buf
->next_element_to_fill
, offset
);
3749 if (!queue
->do_pack
) {
3750 QETH_CARD_TEXT(queue
->card
, 6, "fillbfnp");
3751 /* set state to PRIMED -> will be flushed */
3752 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3755 QETH_CARD_TEXT(queue
->card
, 6, "fillbfpa");
3756 if (queue
->card
->options
.performance_stats
)
3757 queue
->card
->perf_stats
.skbs_sent_pack
++;
3758 if (buf
->next_element_to_fill
>=
3759 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
3761 * packed buffer if full -> set state PRIMED
3762 * -> will be flushed
3764 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3771 int qeth_do_send_packet_fast(struct qeth_card
*card
,
3772 struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
3773 struct qeth_hdr
*hdr
, int elements_needed
,
3774 int offset
, int hd_len
)
3776 struct qeth_qdio_out_buffer
*buffer
;
3779 /* spin until we get the queue ... */
3780 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3781 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3782 /* ... now we've got the queue */
3783 index
= queue
->next_buf_to_fill
;
3784 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3786 * check if buffer is empty to make sure that we do not 'overtake'
3787 * ourselves and try to fill a buffer that is already primed
3789 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
3791 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ 1) %
3792 QDIO_MAX_BUFFERS_PER_Q
;
3793 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3794 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
3795 qeth_flush_buffers(queue
, index
, 1);
3798 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3801 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
3803 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
3804 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
3805 int elements_needed
)
3807 struct qeth_qdio_out_buffer
*buffer
;
3809 int flush_count
= 0;
3814 /* spin until we get the queue ... */
3815 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3816 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3817 start_index
= queue
->next_buf_to_fill
;
3818 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3820 * check if buffer is empty to make sure that we do not 'overtake'
3821 * ourselves and try to fill a buffer that is already primed
3823 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
3824 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3827 /* check if we need to switch packing state of this queue */
3828 qeth_switch_to_packing_if_needed(queue
);
3829 if (queue
->do_pack
) {
3831 /* does packet fit in current buffer? */
3832 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
3833 buffer
->next_element_to_fill
) < elements_needed
) {
3834 /* ... no -> set state PRIMED */
3835 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3837 queue
->next_buf_to_fill
=
3838 (queue
->next_buf_to_fill
+ 1) %
3839 QDIO_MAX_BUFFERS_PER_Q
;
3840 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3841 /* we did a step forward, so check buffer state
3843 if (atomic_read(&buffer
->state
) !=
3844 QETH_QDIO_BUF_EMPTY
) {
3845 qeth_flush_buffers(queue
, start_index
,
3847 atomic_set(&queue
->state
,
3848 QETH_OUT_Q_UNLOCKED
);
3853 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, -1, 0);
3854 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
3855 QDIO_MAX_BUFFERS_PER_Q
;
3858 qeth_flush_buffers(queue
, start_index
, flush_count
);
3859 else if (!atomic_read(&queue
->set_pci_flags_count
))
3860 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
3862 * queue->state will go from LOCKED -> UNLOCKED or from
3863 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3864 * (switch packing state or flush buffer to get another pci flag out).
3865 * In that case we will enter this loop
3867 while (atomic_dec_return(&queue
->state
)) {
3869 start_index
= queue
->next_buf_to_fill
;
3870 /* check if we can go back to non-packing state */
3871 flush_count
+= qeth_switch_to_nonpacking_if_needed(queue
);
3873 * check if we need to flush a packing buffer to get a pci
3874 * flag out on the queue
3876 if (!flush_count
&& !atomic_read(&queue
->set_pci_flags_count
))
3877 flush_count
+= qeth_flush_buffers_on_no_pci(queue
);
3879 qeth_flush_buffers(queue
, start_index
, flush_count
);
3881 /* at this point the queue is UNLOCKED again */
3882 if (queue
->card
->options
.performance_stats
&& do_pack
)
3883 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
3887 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
3889 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
3890 struct qeth_reply
*reply
, unsigned long data
)
3892 struct qeth_ipa_cmd
*cmd
;
3893 struct qeth_ipacmd_setadpparms
*setparms
;
3895 QETH_CARD_TEXT(card
, 4, "prmadpcb");
3897 cmd
= (struct qeth_ipa_cmd
*) data
;
3898 setparms
= &(cmd
->data
.setadapterparms
);
3900 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
3901 if (cmd
->hdr
.return_code
) {
3902 QETH_CARD_TEXT_(card
, 4, "prmrc%2.2x", cmd
->hdr
.return_code
);
3903 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
3905 card
->info
.promisc_mode
= setparms
->data
.mode
;
3909 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
3911 enum qeth_ipa_promisc_modes mode
;
3912 struct net_device
*dev
= card
->dev
;
3913 struct qeth_cmd_buffer
*iob
;
3914 struct qeth_ipa_cmd
*cmd
;
3916 QETH_CARD_TEXT(card
, 4, "setprom");
3918 if (((dev
->flags
& IFF_PROMISC
) &&
3919 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
3920 (!(dev
->flags
& IFF_PROMISC
) &&
3921 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
3923 mode
= SET_PROMISC_MODE_OFF
;
3924 if (dev
->flags
& IFF_PROMISC
)
3925 mode
= SET_PROMISC_MODE_ON
;
3926 QETH_CARD_TEXT_(card
, 4, "mode:%x", mode
);
3928 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
3929 sizeof(struct qeth_ipacmd_setadpparms
));
3930 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
3931 cmd
->data
.setadapterparms
.data
.mode
= mode
;
3932 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
3934 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
3936 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
3938 struct qeth_card
*card
;
3941 card
= dev
->ml_priv
;
3943 QETH_CARD_TEXT(card
, 4, "chgmtu");
3944 sprintf(dbf_text
, "%8x", new_mtu
);
3945 QETH_CARD_TEXT(card
, 4, dbf_text
);
3949 if (new_mtu
> 65535)
3951 if ((!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) &&
3952 (!qeth_mtu_is_valid(card
, new_mtu
)))
3957 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
3959 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
3961 struct qeth_card
*card
;
3963 card
= dev
->ml_priv
;
3965 QETH_CARD_TEXT(card
, 5, "getstat");
3967 return &card
->stats
;
3969 EXPORT_SYMBOL_GPL(qeth_get_stats
);
3971 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
3972 struct qeth_reply
*reply
, unsigned long data
)
3974 struct qeth_ipa_cmd
*cmd
;
3976 QETH_CARD_TEXT(card
, 4, "chgmaccb");
3978 cmd
= (struct qeth_ipa_cmd
*) data
;
3979 if (!card
->options
.layer2
||
3980 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
3981 memcpy(card
->dev
->dev_addr
,
3982 &cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
3984 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
3986 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3990 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
3993 struct qeth_cmd_buffer
*iob
;
3994 struct qeth_ipa_cmd
*cmd
;
3996 QETH_CARD_TEXT(card
, 4, "chgmac");
3998 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
3999 sizeof(struct qeth_ipacmd_setadpparms
));
4000 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4001 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
4002 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= OSA_ADDR_LEN
;
4003 memcpy(&cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4004 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
4005 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
4009 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
4011 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
4012 struct qeth_reply
*reply
, unsigned long data
)
4014 struct qeth_ipa_cmd
*cmd
;
4015 struct qeth_set_access_ctrl
*access_ctrl_req
;
4017 QETH_CARD_TEXT(card
, 4, "setaccb");
4019 cmd
= (struct qeth_ipa_cmd
*) data
;
4020 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4021 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
4022 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4023 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
4024 cmd
->data
.setadapterparms
.hdr
.return_code
);
4025 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4026 case SET_ACCESS_CTRL_RC_SUCCESS
:
4027 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
4028 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
4030 card
->options
.isolation
= access_ctrl_req
->subcmd_code
;
4031 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
4032 dev_info(&card
->gdev
->dev
,
4033 "QDIO data connection isolation is deactivated\n");
4035 dev_info(&card
->gdev
->dev
,
4036 "QDIO data connection isolation is activated\n");
4038 QETH_DBF_MESSAGE(3, "OK:SET_ACCESS_CTRL(%s, %d)==%d\n",
4039 card
->gdev
->dev
.kobj
.name
,
4040 access_ctrl_req
->subcmd_code
,
4041 cmd
->data
.setadapterparms
.hdr
.return_code
);
4044 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
4046 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4047 card
->gdev
->dev
.kobj
.name
,
4048 access_ctrl_req
->subcmd_code
,
4049 cmd
->data
.setadapterparms
.hdr
.return_code
);
4050 dev_err(&card
->gdev
->dev
, "Adapter does not "
4051 "support QDIO data connection isolation\n");
4053 /* ensure isolation mode is "none" */
4054 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4057 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
4059 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
4060 card
->gdev
->dev
.kobj
.name
,
4061 access_ctrl_req
->subcmd_code
,
4062 cmd
->data
.setadapterparms
.hdr
.return_code
);
4063 dev_err(&card
->gdev
->dev
,
4064 "Adapter is dedicated. "
4065 "QDIO data connection isolation not supported\n");
4067 /* ensure isolation mode is "none" */
4068 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4071 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
4073 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
4074 card
->gdev
->dev
.kobj
.name
,
4075 access_ctrl_req
->subcmd_code
,
4076 cmd
->data
.setadapterparms
.hdr
.return_code
);
4077 dev_err(&card
->gdev
->dev
,
4078 "TSO does not permit QDIO data connection isolation\n");
4080 /* ensure isolation mode is "none" */
4081 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4086 /* this should never happen */
4087 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d"
4089 card
->gdev
->dev
.kobj
.name
,
4090 access_ctrl_req
->subcmd_code
,
4091 cmd
->data
.setadapterparms
.hdr
.return_code
);
4093 /* ensure isolation mode is "none" */
4094 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4098 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4102 static int qeth_setadpparms_set_access_ctrl(struct qeth_card
*card
,
4103 enum qeth_ipa_isolation_modes isolation
)
4106 struct qeth_cmd_buffer
*iob
;
4107 struct qeth_ipa_cmd
*cmd
;
4108 struct qeth_set_access_ctrl
*access_ctrl_req
;
4110 QETH_CARD_TEXT(card
, 4, "setacctl");
4112 QETH_DBF_TEXT_(SETUP
, 2, "setacctl");
4113 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4115 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_ACCESS_CONTROL
,
4116 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4117 sizeof(struct qeth_set_access_ctrl
));
4118 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4119 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4120 access_ctrl_req
->subcmd_code
= isolation
;
4122 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_set_access_ctrl_cb
,
4124 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d", rc
);
4128 int qeth_set_access_ctrl_online(struct qeth_card
*card
)
4132 QETH_CARD_TEXT(card
, 4, "setactlo");
4134 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
4135 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
4136 qeth_adp_supported(card
, IPA_SETADP_SET_ACCESS_CONTROL
)) {
4137 rc
= qeth_setadpparms_set_access_ctrl(card
,
4138 card
->options
.isolation
);
4141 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4142 card
->gdev
->dev
.kobj
.name
,
4145 } else if (card
->options
.isolation
!= ISOLATION_MODE_NONE
) {
4146 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4148 dev_err(&card
->gdev
->dev
, "Adapter does not "
4149 "support QDIO data connection isolation\n");
4154 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online
);
4156 void qeth_tx_timeout(struct net_device
*dev
)
4158 struct qeth_card
*card
;
4160 card
= dev
->ml_priv
;
4161 QETH_CARD_TEXT(card
, 4, "txtimeo");
4162 card
->stats
.tx_errors
++;
4163 qeth_schedule_recovery(card
);
4165 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
4167 int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
4169 struct qeth_card
*card
= dev
->ml_priv
;
4173 case MII_BMCR
: /* Basic mode control register */
4175 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
4176 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
4177 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
4178 rc
|= BMCR_SPEED100
;
4180 case MII_BMSR
: /* Basic mode status register */
4181 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
4182 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
4185 case MII_PHYSID1
: /* PHYS ID 1 */
4186 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
4188 rc
= (rc
>> 5) & 0xFFFF;
4190 case MII_PHYSID2
: /* PHYS ID 2 */
4191 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
4193 case MII_ADVERTISE
: /* Advertisement control reg */
4196 case MII_LPA
: /* Link partner ability reg */
4197 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
4198 LPA_100BASE4
| LPA_LPACK
;
4200 case MII_EXPANSION
: /* Expansion register */
4202 case MII_DCOUNTER
: /* disconnect counter */
4204 case MII_FCSCOUNTER
: /* false carrier counter */
4206 case MII_NWAYTEST
: /* N-way auto-neg test register */
4208 case MII_RERRCOUNTER
: /* rx error counter */
4209 rc
= card
->stats
.rx_errors
;
4211 case MII_SREVISION
: /* silicon revision */
4213 case MII_RESV1
: /* reserved 1 */
4215 case MII_LBRERROR
: /* loopback, rx, bypass error */
4217 case MII_PHYADDR
: /* physical address */
4219 case MII_RESV2
: /* reserved 2 */
4221 case MII_TPISTATUS
: /* TPI status for 10mbps */
4223 case MII_NCONFIG
: /* network interface config */
4230 EXPORT_SYMBOL_GPL(qeth_mdio_read
);
4232 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
4233 struct qeth_cmd_buffer
*iob
, int len
,
4234 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
4240 QETH_CARD_TEXT(card
, 4, "sendsnmp");
4242 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
4243 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
4244 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
4245 /* adjust PDU length fields in IPA_PDU_HEADER */
4246 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
4248 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
4249 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
4250 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
4251 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
4252 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
4253 reply_cb
, reply_param
);
4256 static int qeth_snmp_command_cb(struct qeth_card
*card
,
4257 struct qeth_reply
*reply
, unsigned long sdata
)
4259 struct qeth_ipa_cmd
*cmd
;
4260 struct qeth_arp_query_info
*qinfo
;
4261 struct qeth_snmp_cmd
*snmp
;
4262 unsigned char *data
;
4265 QETH_CARD_TEXT(card
, 3, "snpcmdcb");
4267 cmd
= (struct qeth_ipa_cmd
*) sdata
;
4268 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
4269 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
4270 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
4272 if (cmd
->hdr
.return_code
) {
4273 QETH_CARD_TEXT_(card
, 4, "scer1%i", cmd
->hdr
.return_code
);
4276 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4277 cmd
->hdr
.return_code
=
4278 cmd
->data
.setadapterparms
.hdr
.return_code
;
4279 QETH_CARD_TEXT_(card
, 4, "scer2%i", cmd
->hdr
.return_code
);
4282 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
4283 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
4284 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
4286 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
4288 /* check if there is enough room in userspace */
4289 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
4290 QETH_CARD_TEXT_(card
, 4, "scer3%i", -ENOMEM
);
4291 cmd
->hdr
.return_code
= -ENOMEM
;
4294 QETH_CARD_TEXT_(card
, 4, "snore%i",
4295 cmd
->data
.setadapterparms
.hdr
.used_total
);
4296 QETH_CARD_TEXT_(card
, 4, "sseqn%i",
4297 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4298 /*copy entries to user buffer*/
4299 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
4300 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4302 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
4303 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
4305 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4306 (char *)&snmp
->request
, data_len
);
4308 qinfo
->udata_offset
+= data_len
;
4309 /* check if all replies received ... */
4310 QETH_CARD_TEXT_(card
, 4, "srtot%i",
4311 cmd
->data
.setadapterparms
.hdr
.used_total
);
4312 QETH_CARD_TEXT_(card
, 4, "srseq%i",
4313 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4314 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4315 cmd
->data
.setadapterparms
.hdr
.used_total
)
4320 int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
4322 struct qeth_cmd_buffer
*iob
;
4323 struct qeth_ipa_cmd
*cmd
;
4324 struct qeth_snmp_ureq
*ureq
;
4326 struct qeth_arp_query_info qinfo
= {0, };
4329 QETH_CARD_TEXT(card
, 3, "snmpcmd");
4331 if (card
->info
.guestlan
)
4334 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
4335 (!card
->options
.layer2
)) {
4338 /* skip 4 bytes (data_len struct member) to get req_len */
4339 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
4341 ureq
= memdup_user(udata
, req_len
+ sizeof(struct qeth_snmp_ureq_hdr
));
4343 QETH_CARD_TEXT(card
, 2, "snmpnome");
4344 return PTR_ERR(ureq
);
4346 qinfo
.udata_len
= ureq
->hdr
.data_len
;
4347 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
4352 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
4354 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
4355 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
4356 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4357 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
4358 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
4359 qeth_snmp_command_cb
, (void *)&qinfo
);
4361 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4362 QETH_CARD_IFNAME(card
), rc
);
4364 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
4372 EXPORT_SYMBOL_GPL(qeth_snmp_command
);
4374 static inline int qeth_get_qdio_q_format(struct qeth_card
*card
)
4376 switch (card
->info
.type
) {
4377 case QETH_CARD_TYPE_IQD
:
4384 static void qeth_determine_capabilities(struct qeth_card
*card
)
4389 struct ccw_device
*ddev
;
4390 int ddev_offline
= 0;
4392 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4393 ddev
= CARD_DDEV(card
);
4394 if (!ddev
->online
) {
4396 rc
= ccw_device_set_online(ddev
);
4398 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4403 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4405 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4406 dev_name(&card
->gdev
->dev
), rc
);
4407 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4410 qeth_configure_unitaddr(card
, prcd
);
4411 qeth_configure_blkt_default(card
, prcd
);
4414 rc
= qdio_get_ssqd_desc(ddev
, &card
->ssqd
);
4416 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4418 QETH_DBF_TEXT_(SETUP
, 2, "qfmt%d", card
->ssqd
.qfmt
);
4419 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac1
);
4420 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac3
);
4421 QETH_DBF_TEXT_(SETUP
, 2, "icnt%d", card
->ssqd
.icnt
);
4422 if (!((card
->ssqd
.qfmt
!= QDIO_IQDIO_QFMT
) ||
4423 ((card
->ssqd
.qdioac1
& CHSC_AC1_INITIATE_INPUTQ
) == 0) ||
4424 ((card
->ssqd
.qdioac3
& CHSC_AC3_FORMAT2_CQ_AVAILABLE
) == 0))) {
4425 dev_info(&card
->gdev
->dev
,
4426 "Completion Queueing supported\n");
4428 card
->options
.cq
= QETH_CQ_NOTAVAILABLE
;
4433 if (ddev_offline
== 1)
4434 ccw_device_set_offline(ddev
);
4439 static inline void qeth_qdio_establish_cq(struct qeth_card
*card
,
4440 struct qdio_buffer
**in_sbal_ptrs
,
4441 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long)) {
4444 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
4445 int offset
= QDIO_MAX_BUFFERS_PER_Q
*
4446 (card
->qdio
.no_in_queues
- 1);
4447 i
= QDIO_MAX_BUFFERS_PER_Q
* (card
->qdio
.no_in_queues
- 1);
4448 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4449 in_sbal_ptrs
[offset
+ i
] = (struct qdio_buffer
*)
4450 virt_to_phys(card
->qdio
.c_q
->bufs
[i
].buffer
);
4453 queue_start_poll
[card
->qdio
.no_in_queues
- 1] = NULL
;
4457 static int qeth_qdio_establish(struct qeth_card
*card
)
4459 struct qdio_initialize init_data
;
4460 char *qib_param_field
;
4461 struct qdio_buffer
**in_sbal_ptrs
;
4462 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long);
4463 struct qdio_buffer
**out_sbal_ptrs
;
4467 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
4469 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
4471 if (!qib_param_field
) {
4473 goto out_free_nothing
;
4476 qeth_create_qib_param_field(card
, qib_param_field
);
4477 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
4479 in_sbal_ptrs
= kzalloc(card
->qdio
.no_in_queues
*
4480 QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
4482 if (!in_sbal_ptrs
) {
4484 goto out_free_qib_param
;
4486 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4487 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
4488 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
4491 queue_start_poll
= kzalloc(sizeof(void *) * card
->qdio
.no_in_queues
,
4493 if (!queue_start_poll
) {
4495 goto out_free_in_sbals
;
4497 for (i
= 0; i
< card
->qdio
.no_in_queues
; ++i
)
4498 queue_start_poll
[i
] = card
->discipline
.start_poll
;
4500 qeth_qdio_establish_cq(card
, in_sbal_ptrs
, queue_start_poll
);
4503 kzalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
4504 sizeof(void *), GFP_KERNEL
);
4505 if (!out_sbal_ptrs
) {
4507 goto out_free_queue_start_poll
;
4509 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
4510 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
4511 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
4512 card
->qdio
.out_qs
[i
]->bufs
[j
]->buffer
);
4515 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
4516 init_data
.cdev
= CARD_DDEV(card
);
4517 init_data
.q_format
= qeth_get_qdio_q_format(card
);
4518 init_data
.qib_param_field_format
= 0;
4519 init_data
.qib_param_field
= qib_param_field
;
4520 init_data
.no_input_qs
= card
->qdio
.no_in_queues
;
4521 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
4522 init_data
.input_handler
= card
->discipline
.input_handler
;
4523 init_data
.output_handler
= card
->discipline
.output_handler
;
4524 init_data
.queue_start_poll
= queue_start_poll
;
4525 init_data
.int_parm
= (unsigned long) card
;
4526 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
4527 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
4528 init_data
.output_sbal_state_array
= card
->qdio
.out_bufstates
;
4529 init_data
.scan_threshold
=
4530 (card
->info
.type
== QETH_CARD_TYPE_IQD
) ? 8 : 32;
4532 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
4533 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
4534 rc
= qdio_allocate(&init_data
);
4536 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4539 rc
= qdio_establish(&init_data
);
4541 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4542 qdio_free(CARD_DDEV(card
));
4546 switch (card
->options
.cq
) {
4547 case QETH_CQ_ENABLED
:
4548 dev_info(&card
->gdev
->dev
, "Completion Queue support enabled");
4550 case QETH_CQ_DISABLED
:
4551 dev_info(&card
->gdev
->dev
, "Completion Queue support disabled");
4557 kfree(out_sbal_ptrs
);
4558 out_free_queue_start_poll
:
4559 kfree(queue_start_poll
);
4561 kfree(in_sbal_ptrs
);
4563 kfree(qib_param_field
);
4568 static void qeth_core_free_card(struct qeth_card
*card
)
4571 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
4572 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
4573 qeth_clean_channel(&card
->read
);
4574 qeth_clean_channel(&card
->write
);
4576 free_netdev(card
->dev
);
4577 kfree(card
->ip_tbd_list
);
4578 qeth_free_qdio_buffers(card
);
4579 unregister_service_level(&card
->qeth_service_level
);
4583 static struct ccw_device_id qeth_ids
[] = {
4584 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
4585 .driver_info
= QETH_CARD_TYPE_OSD
},
4586 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
4587 .driver_info
= QETH_CARD_TYPE_IQD
},
4588 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
4589 .driver_info
= QETH_CARD_TYPE_OSN
},
4590 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
4591 .driver_info
= QETH_CARD_TYPE_OSM
},
4592 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
4593 .driver_info
= QETH_CARD_TYPE_OSX
},
4596 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
4598 static struct ccw_driver qeth_ccw_driver
= {
4600 .owner
= THIS_MODULE
,
4604 .probe
= ccwgroup_probe_ccwdev
,
4605 .remove
= ccwgroup_remove_ccwdev
,
4608 static int qeth_core_driver_group(const char *buf
, struct device
*root_dev
,
4609 unsigned long driver_id
)
4611 return ccwgroup_create_from_string(root_dev
, driver_id
,
4612 &qeth_ccw_driver
, 3, buf
);
4615 int qeth_core_hardsetup_card(struct qeth_card
*card
)
4620 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
4621 atomic_set(&card
->force_alloc_skb
, 0);
4622 qeth_get_channel_path_desc(card
);
4625 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
4626 dev_name(&card
->gdev
->dev
));
4627 ccw_device_set_offline(CARD_DDEV(card
));
4628 ccw_device_set_offline(CARD_WDEV(card
));
4629 ccw_device_set_offline(CARD_RDEV(card
));
4630 rc
= ccw_device_set_online(CARD_RDEV(card
));
4633 rc
= ccw_device_set_online(CARD_WDEV(card
));
4636 rc
= ccw_device_set_online(CARD_DDEV(card
));
4639 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
4641 if (rc
== -ERESTARTSYS
) {
4642 QETH_DBF_TEXT(SETUP
, 2, "break1");
4645 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
4651 qeth_determine_capabilities(card
);
4652 qeth_init_tokens(card
);
4653 qeth_init_func_level(card
);
4654 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
4655 if (rc
== -ERESTARTSYS
) {
4656 QETH_DBF_TEXT(SETUP
, 2, "break2");
4659 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4665 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
4666 if (rc
== -ERESTARTSYS
) {
4667 QETH_DBF_TEXT(SETUP
, 2, "break3");
4670 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
4676 card
->read_or_write_problem
= 0;
4677 rc
= qeth_mpc_initialize(card
);
4679 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4683 card
->options
.ipa4
.supported_funcs
= 0;
4684 card
->options
.adp
.supported_funcs
= 0;
4685 card
->info
.diagass_support
= 0;
4686 qeth_query_ipassists(card
, QETH_PROT_IPV4
);
4687 if (qeth_is_supported(card
, IPA_SETADAPTERPARMS
))
4688 qeth_query_setadapterparms(card
);
4689 if (qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
))
4690 qeth_query_setdiagass(card
);
4693 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
4694 "an error on the device\n");
4695 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
4696 dev_name(&card
->gdev
->dev
), rc
);
4699 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
4701 static inline int qeth_create_skb_frag(struct qeth_qdio_buffer
*qethbuffer
,
4702 struct qdio_buffer_element
*element
,
4703 struct sk_buff
**pskb
, int offset
, int *pfrag
, int data_len
)
4705 struct page
*page
= virt_to_page(element
->addr
);
4706 if (*pskb
== NULL
) {
4707 if (qethbuffer
->rx_skb
) {
4708 /* only if qeth_card.options.cq == QETH_CQ_ENABLED */
4709 *pskb
= qethbuffer
->rx_skb
;
4710 qethbuffer
->rx_skb
= NULL
;
4712 *pskb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
4717 skb_reserve(*pskb
, ETH_HLEN
);
4718 if (data_len
<= QETH_RX_PULL_LEN
) {
4719 memcpy(skb_put(*pskb
, data_len
), element
->addr
+ offset
,
4723 memcpy(skb_put(*pskb
, QETH_RX_PULL_LEN
),
4724 element
->addr
+ offset
, QETH_RX_PULL_LEN
);
4725 skb_fill_page_desc(*pskb
, *pfrag
, page
,
4726 offset
+ QETH_RX_PULL_LEN
,
4727 data_len
- QETH_RX_PULL_LEN
);
4728 (*pskb
)->data_len
+= data_len
- QETH_RX_PULL_LEN
;
4729 (*pskb
)->len
+= data_len
- QETH_RX_PULL_LEN
;
4730 (*pskb
)->truesize
+= data_len
- QETH_RX_PULL_LEN
;
4735 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
, data_len
);
4736 (*pskb
)->data_len
+= data_len
;
4737 (*pskb
)->len
+= data_len
;
4738 (*pskb
)->truesize
+= data_len
;
4746 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
4747 struct qeth_qdio_buffer
*qethbuffer
,
4748 struct qdio_buffer_element
**__element
, int *__offset
,
4749 struct qeth_hdr
**hdr
)
4751 struct qdio_buffer_element
*element
= *__element
;
4752 struct qdio_buffer
*buffer
= qethbuffer
->buffer
;
4753 int offset
= *__offset
;
4754 struct sk_buff
*skb
= NULL
;
4762 /* qeth_hdr must not cross element boundaries */
4763 if (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
4764 if (qeth_is_last_sbale(element
))
4768 if (element
->length
< sizeof(struct qeth_hdr
))
4771 *hdr
= element
->addr
+ offset
;
4773 offset
+= sizeof(struct qeth_hdr
);
4774 switch ((*hdr
)->hdr
.l2
.id
) {
4775 case QETH_HEADER_TYPE_LAYER2
:
4776 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
4778 case QETH_HEADER_TYPE_LAYER3
:
4779 skb_len
= (*hdr
)->hdr
.l3
.length
;
4780 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
4781 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
))
4784 headroom
= ETH_HLEN
;
4786 case QETH_HEADER_TYPE_OSN
:
4787 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
4788 headroom
= sizeof(struct qeth_hdr
);
4797 if (((skb_len
>= card
->options
.rx_sg_cb
) &&
4798 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
4799 (!atomic_read(&card
->force_alloc_skb
))) ||
4800 (card
->options
.cq
== QETH_CQ_ENABLED
)) {
4803 skb
= dev_alloc_skb(skb_len
+ headroom
);
4807 skb_reserve(skb
, headroom
);
4810 data_ptr
= element
->addr
+ offset
;
4812 data_len
= min(skb_len
, (int)(element
->length
- offset
));
4815 if (qeth_create_skb_frag(qethbuffer
, element
,
4816 &skb
, offset
, &frag
, data_len
))
4819 memcpy(skb_put(skb
, data_len
), data_ptr
,
4823 skb_len
-= data_len
;
4825 if (qeth_is_last_sbale(element
)) {
4826 QETH_CARD_TEXT(card
, 4, "unexeob");
4827 QETH_CARD_HEX(card
, 2, buffer
, sizeof(void *));
4828 dev_kfree_skb_any(skb
);
4829 card
->stats
.rx_errors
++;
4834 data_ptr
= element
->addr
;
4839 *__element
= element
;
4841 if (use_rx_sg
&& card
->options
.performance_stats
) {
4842 card
->perf_stats
.sg_skbs_rx
++;
4843 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
4847 if (net_ratelimit()) {
4848 QETH_CARD_TEXT(card
, 2, "noskbmem");
4850 card
->stats
.rx_dropped
++;
4853 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
4855 static void qeth_unregister_dbf_views(void)
4858 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
4859 debug_unregister(qeth_dbf
[x
].id
);
4860 qeth_dbf
[x
].id
= NULL
;
4864 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *fmt
, ...)
4866 char dbf_txt_buf
[32];
4869 if (level
> id
->level
)
4871 va_start(args
, fmt
);
4872 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
4874 debug_text_event(id
, level
, dbf_txt_buf
);
4876 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
4878 static int qeth_register_dbf_views(void)
4883 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
4884 /* register the areas */
4885 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
4889 if (qeth_dbf
[x
].id
== NULL
) {
4890 qeth_unregister_dbf_views();
4894 /* register a view */
4895 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
4897 qeth_unregister_dbf_views();
4901 /* set a passing level */
4902 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
4908 int qeth_core_load_discipline(struct qeth_card
*card
,
4909 enum qeth_discipline_id discipline
)
4912 switch (discipline
) {
4913 case QETH_DISCIPLINE_LAYER3
:
4914 card
->discipline
.ccwgdriver
= try_then_request_module(
4915 symbol_get(qeth_l3_ccwgroup_driver
),
4918 case QETH_DISCIPLINE_LAYER2
:
4919 card
->discipline
.ccwgdriver
= try_then_request_module(
4920 symbol_get(qeth_l2_ccwgroup_driver
),
4924 if (!card
->discipline
.ccwgdriver
) {
4925 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
4926 "support discipline %d\n", discipline
);
4932 void qeth_core_free_discipline(struct qeth_card
*card
)
4934 if (card
->options
.layer2
)
4935 symbol_put(qeth_l2_ccwgroup_driver
);
4937 symbol_put(qeth_l3_ccwgroup_driver
);
4938 card
->discipline
.ccwgdriver
= NULL
;
4941 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
4943 struct qeth_card
*card
;
4946 unsigned long flags
;
4949 QETH_DBF_TEXT(SETUP
, 2, "probedev");
4952 if (!get_device(dev
))
4955 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
4957 card
= qeth_alloc_card();
4959 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
4964 snprintf(dbf_name
, sizeof(dbf_name
), "qeth_card_%s",
4965 dev_name(&gdev
->dev
));
4966 card
->debug
= debug_register(dbf_name
, 2, 1, 8);
4968 QETH_DBF_TEXT_(SETUP
, 2, "%s", "qcdbf");
4972 debug_register_view(card
->debug
, &debug_hex_ascii_view
);
4974 card
->read
.ccwdev
= gdev
->cdev
[0];
4975 card
->write
.ccwdev
= gdev
->cdev
[1];
4976 card
->data
.ccwdev
= gdev
->cdev
[2];
4977 dev_set_drvdata(&gdev
->dev
, card
);
4979 gdev
->cdev
[0]->handler
= qeth_irq
;
4980 gdev
->cdev
[1]->handler
= qeth_irq
;
4981 gdev
->cdev
[2]->handler
= qeth_irq
;
4983 rc
= qeth_determine_card_type(card
);
4985 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4988 rc
= qeth_setup_card(card
);
4990 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
4994 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
4995 rc
= qeth_core_create_osn_attributes(dev
);
4997 rc
= qeth_core_create_device_attributes(dev
);
5000 switch (card
->info
.type
) {
5001 case QETH_CARD_TYPE_OSN
:
5002 case QETH_CARD_TYPE_OSM
:
5003 rc
= qeth_core_load_discipline(card
, QETH_DISCIPLINE_LAYER2
);
5006 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
5009 case QETH_CARD_TYPE_OSD
:
5010 case QETH_CARD_TYPE_OSX
:
5015 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5016 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
5017 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5019 qeth_determine_capabilities(card
);
5023 qeth_core_free_discipline(card
);
5025 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
5026 qeth_core_remove_osn_attributes(dev
);
5028 qeth_core_remove_device_attributes(dev
);
5030 debug_unregister(card
->debug
);
5032 qeth_core_free_card(card
);
5038 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
5040 unsigned long flags
;
5041 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5043 QETH_DBF_TEXT(SETUP
, 2, "removedv");
5045 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
5046 qeth_core_remove_osn_attributes(&gdev
->dev
);
5048 qeth_core_remove_device_attributes(&gdev
->dev
);
5051 if (card
->discipline
.ccwgdriver
) {
5052 card
->discipline
.ccwgdriver
->remove(gdev
);
5053 qeth_core_free_discipline(card
);
5056 debug_unregister(card
->debug
);
5057 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5058 list_del(&card
->list
);
5059 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5060 qeth_core_free_card(card
);
5061 dev_set_drvdata(&gdev
->dev
, NULL
);
5062 put_device(&gdev
->dev
);
5066 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
5068 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5072 if (!card
->discipline
.ccwgdriver
) {
5073 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
5074 def_discipline
= QETH_DISCIPLINE_LAYER3
;
5076 def_discipline
= QETH_DISCIPLINE_LAYER2
;
5077 rc
= qeth_core_load_discipline(card
, def_discipline
);
5080 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
5084 rc
= card
->discipline
.ccwgdriver
->set_online(gdev
);
5089 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
5091 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5092 return card
->discipline
.ccwgdriver
->set_offline(gdev
);
5095 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
5097 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5098 if (card
->discipline
.ccwgdriver
&&
5099 card
->discipline
.ccwgdriver
->shutdown
)
5100 card
->discipline
.ccwgdriver
->shutdown(gdev
);
5103 static int qeth_core_prepare(struct ccwgroup_device
*gdev
)
5105 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5106 if (card
->discipline
.ccwgdriver
&&
5107 card
->discipline
.ccwgdriver
->prepare
)
5108 return card
->discipline
.ccwgdriver
->prepare(gdev
);
5112 static void qeth_core_complete(struct ccwgroup_device
*gdev
)
5114 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5115 if (card
->discipline
.ccwgdriver
&&
5116 card
->discipline
.ccwgdriver
->complete
)
5117 card
->discipline
.ccwgdriver
->complete(gdev
);
5120 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
5122 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5123 if (card
->discipline
.ccwgdriver
&&
5124 card
->discipline
.ccwgdriver
->freeze
)
5125 return card
->discipline
.ccwgdriver
->freeze(gdev
);
5129 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
5131 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5132 if (card
->discipline
.ccwgdriver
&&
5133 card
->discipline
.ccwgdriver
->thaw
)
5134 return card
->discipline
.ccwgdriver
->thaw(gdev
);
5138 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
5140 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5141 if (card
->discipline
.ccwgdriver
&&
5142 card
->discipline
.ccwgdriver
->restore
)
5143 return card
->discipline
.ccwgdriver
->restore(gdev
);
5147 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
5149 .owner
= THIS_MODULE
,
5152 .driver_id
= 0xD8C5E3C8,
5153 .probe
= qeth_core_probe_device
,
5154 .remove
= qeth_core_remove_device
,
5155 .set_online
= qeth_core_set_online
,
5156 .set_offline
= qeth_core_set_offline
,
5157 .shutdown
= qeth_core_shutdown
,
5158 .prepare
= qeth_core_prepare
,
5159 .complete
= qeth_core_complete
,
5160 .freeze
= qeth_core_freeze
,
5161 .thaw
= qeth_core_thaw
,
5162 .restore
= qeth_core_restore
,
5166 qeth_core_driver_group_store(struct device_driver
*ddrv
, const char *buf
,
5170 err
= qeth_core_driver_group(buf
, qeth_core_root_dev
,
5171 qeth_core_ccwgroup_driver
.driver_id
);
5178 static DRIVER_ATTR(group
, 0200, NULL
, qeth_core_driver_group_store
);
5181 const char str
[ETH_GSTRING_LEN
];
5182 } qeth_ethtool_stats_keys
[] = {
5187 {"tx skbs no packing"},
5188 {"tx buffers no packing"},
5189 {"tx skbs packing"},
5190 {"tx buffers packing"},
5193 /* 10 */{"rx sg skbs"},
5195 {"rx sg page allocs"},
5196 {"tx large kbytes"},
5198 {"tx pk state ch n->p"},
5199 {"tx pk state ch p->n"},
5200 {"tx pk watermark low"},
5201 {"tx pk watermark high"},
5202 {"queue 0 buffer usage"},
5203 /* 20 */{"queue 1 buffer usage"},
5204 {"queue 2 buffer usage"},
5205 {"queue 3 buffer usage"},
5208 {"rx do_QDIO time"},
5209 {"rx do_QDIO count"},
5210 {"tx handler time"},
5211 {"tx handler count"},
5213 /* 30 */{"tx count"},
5214 {"tx do_QDIO time"},
5215 {"tx do_QDIO count"},
5218 {"cq handler count"},
5222 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
5224 switch (stringset
) {
5226 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
5231 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
5233 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
5234 struct ethtool_stats
*stats
, u64
*data
)
5236 struct qeth_card
*card
= dev
->ml_priv
;
5237 data
[0] = card
->stats
.rx_packets
-
5238 card
->perf_stats
.initial_rx_packets
;
5239 data
[1] = card
->perf_stats
.bufs_rec
;
5240 data
[2] = card
->stats
.tx_packets
-
5241 card
->perf_stats
.initial_tx_packets
;
5242 data
[3] = card
->perf_stats
.bufs_sent
;
5243 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
5244 - card
->perf_stats
.skbs_sent_pack
;
5245 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
5246 data
[6] = card
->perf_stats
.skbs_sent_pack
;
5247 data
[7] = card
->perf_stats
.bufs_sent_pack
;
5248 data
[8] = card
->perf_stats
.sg_skbs_sent
;
5249 data
[9] = card
->perf_stats
.sg_frags_sent
;
5250 data
[10] = card
->perf_stats
.sg_skbs_rx
;
5251 data
[11] = card
->perf_stats
.sg_frags_rx
;
5252 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
5253 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
5254 data
[14] = card
->perf_stats
.large_send_cnt
;
5255 data
[15] = card
->perf_stats
.sc_dp_p
;
5256 data
[16] = card
->perf_stats
.sc_p_dp
;
5257 data
[17] = QETH_LOW_WATERMARK_PACK
;
5258 data
[18] = QETH_HIGH_WATERMARK_PACK
;
5259 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
5260 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
5261 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
5262 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
5263 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
5264 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
5265 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
5266 data
[23] = card
->perf_stats
.inbound_time
;
5267 data
[24] = card
->perf_stats
.inbound_cnt
;
5268 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
5269 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
5270 data
[27] = card
->perf_stats
.outbound_handler_time
;
5271 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
5272 data
[29] = card
->perf_stats
.outbound_time
;
5273 data
[30] = card
->perf_stats
.outbound_cnt
;
5274 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
5275 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
5276 data
[33] = card
->perf_stats
.tx_csum
;
5277 data
[34] = card
->perf_stats
.tx_lin
;
5278 data
[35] = card
->perf_stats
.cq_cnt
;
5279 data
[36] = card
->perf_stats
.cq_time
;
5281 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
5283 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
5285 switch (stringset
) {
5287 memcpy(data
, &qeth_ethtool_stats_keys
,
5288 sizeof(qeth_ethtool_stats_keys
));
5295 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
5297 void qeth_core_get_drvinfo(struct net_device
*dev
,
5298 struct ethtool_drvinfo
*info
)
5300 struct qeth_card
*card
= dev
->ml_priv
;
5301 if (card
->options
.layer2
)
5302 strcpy(info
->driver
, "qeth_l2");
5304 strcpy(info
->driver
, "qeth_l3");
5306 strcpy(info
->version
, "1.0");
5307 strcpy(info
->fw_version
, card
->info
.mcl_level
);
5308 sprintf(info
->bus_info
, "%s/%s/%s",
5311 CARD_DDEV_ID(card
));
5313 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
5315 int qeth_core_ethtool_get_settings(struct net_device
*netdev
,
5316 struct ethtool_cmd
*ecmd
)
5318 struct qeth_card
*card
= netdev
->ml_priv
;
5319 enum qeth_link_types link_type
;
5321 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
5322 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
5324 link_type
= card
->info
.link_type
;
5326 ecmd
->transceiver
= XCVR_INTERNAL
;
5327 ecmd
->supported
= SUPPORTED_Autoneg
;
5328 ecmd
->advertising
= ADVERTISED_Autoneg
;
5329 ecmd
->duplex
= DUPLEX_FULL
;
5330 ecmd
->autoneg
= AUTONEG_ENABLE
;
5332 switch (link_type
) {
5333 case QETH_LINK_TYPE_FAST_ETH
:
5334 case QETH_LINK_TYPE_LANE_ETH100
:
5335 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
5336 SUPPORTED_10baseT_Full
|
5337 SUPPORTED_100baseT_Half
|
5338 SUPPORTED_100baseT_Full
|
5340 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
5341 ADVERTISED_10baseT_Full
|
5342 ADVERTISED_100baseT_Half
|
5343 ADVERTISED_100baseT_Full
|
5345 ecmd
->speed
= SPEED_100
;
5346 ecmd
->port
= PORT_TP
;
5349 case QETH_LINK_TYPE_GBIT_ETH
:
5350 case QETH_LINK_TYPE_LANE_ETH1000
:
5351 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
5352 SUPPORTED_10baseT_Full
|
5353 SUPPORTED_100baseT_Half
|
5354 SUPPORTED_100baseT_Full
|
5355 SUPPORTED_1000baseT_Half
|
5356 SUPPORTED_1000baseT_Full
|
5358 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
5359 ADVERTISED_10baseT_Full
|
5360 ADVERTISED_100baseT_Half
|
5361 ADVERTISED_100baseT_Full
|
5362 ADVERTISED_1000baseT_Half
|
5363 ADVERTISED_1000baseT_Full
|
5365 ecmd
->speed
= SPEED_1000
;
5366 ecmd
->port
= PORT_FIBRE
;
5369 case QETH_LINK_TYPE_10GBIT_ETH
:
5370 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
5371 SUPPORTED_10baseT_Full
|
5372 SUPPORTED_100baseT_Half
|
5373 SUPPORTED_100baseT_Full
|
5374 SUPPORTED_1000baseT_Half
|
5375 SUPPORTED_1000baseT_Full
|
5376 SUPPORTED_10000baseT_Full
|
5378 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
5379 ADVERTISED_10baseT_Full
|
5380 ADVERTISED_100baseT_Half
|
5381 ADVERTISED_100baseT_Full
|
5382 ADVERTISED_1000baseT_Half
|
5383 ADVERTISED_1000baseT_Full
|
5384 ADVERTISED_10000baseT_Full
|
5386 ecmd
->speed
= SPEED_10000
;
5387 ecmd
->port
= PORT_FIBRE
;
5391 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
5392 SUPPORTED_10baseT_Full
|
5394 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
5395 ADVERTISED_10baseT_Full
|
5397 ecmd
->speed
= SPEED_10
;
5398 ecmd
->port
= PORT_TP
;
5403 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings
);
5405 static int __init
qeth_core_init(void)
5409 pr_info("loading core functions\n");
5410 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
5411 rwlock_init(&qeth_core_card_list
.rwlock
);
5413 rc
= qeth_register_dbf_views();
5416 rc
= ccw_driver_register(&qeth_ccw_driver
);
5419 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
5422 rc
= driver_create_file(&qeth_core_ccwgroup_driver
.driver
,
5423 &driver_attr_group
);
5426 qeth_core_root_dev
= root_device_register("qeth");
5427 rc
= IS_ERR(qeth_core_root_dev
) ? PTR_ERR(qeth_core_root_dev
) : 0;
5431 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
5432 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
5433 if (!qeth_core_header_cache
) {
5438 qeth_qdio_outbuf_cache
= kmem_cache_create("qeth_buf",
5439 sizeof(struct qeth_qdio_out_buffer
), 0, 0, NULL
);
5440 if (!qeth_qdio_outbuf_cache
) {
5447 kmem_cache_destroy(qeth_core_header_cache
);
5449 root_device_unregister(qeth_core_root_dev
);
5451 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
5452 &driver_attr_group
);
5454 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
5456 ccw_driver_unregister(&qeth_ccw_driver
);
5458 QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc
);
5459 qeth_unregister_dbf_views();
5461 pr_err("Initializing the qeth device driver failed\n");
5465 static void __exit
qeth_core_exit(void)
5467 root_device_unregister(qeth_core_root_dev
);
5468 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
5469 &driver_attr_group
);
5470 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
5471 ccw_driver_unregister(&qeth_ccw_driver
);
5472 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
5473 kmem_cache_destroy(qeth_core_header_cache
);
5474 qeth_unregister_dbf_views();
5475 pr_info("core functions removed\n");
5478 module_init(qeth_core_init
);
5479 module_exit(qeth_core_exit
);
5480 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
5481 MODULE_DESCRIPTION("qeth core functions");
5482 MODULE_LICENSE("GPL");