2 * drivers/s390/net/qeth_core_main.c
4 * Copyright IBM Corp. 2007
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>
24 #include <asm/ebcdic.h>
27 #include "qeth_core.h"
29 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
30 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
32 [QETH_DBF_SETUP
] = {"qeth_setup",
33 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
34 [QETH_DBF_QERR
] = {"qeth_qerr",
35 2, 1, 8, 2, &debug_hex_ascii_view
, NULL
},
36 [QETH_DBF_TRACE
] = {"qeth_trace",
37 4, 1, 8, 3, &debug_hex_ascii_view
, NULL
},
38 [QETH_DBF_MSG
] = {"qeth_msg",
39 8, 1, 128, 3, &debug_sprintf_view
, NULL
},
40 [QETH_DBF_SENSE
] = {"qeth_sense",
41 2, 1, 64, 2, &debug_hex_ascii_view
, NULL
},
42 [QETH_DBF_MISC
] = {"qeth_misc",
43 2, 1, 256, 2, &debug_hex_ascii_view
, NULL
},
44 [QETH_DBF_CTRL
] = {"qeth_control",
45 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
47 EXPORT_SYMBOL_GPL(qeth_dbf
);
49 struct qeth_card_list_struct qeth_core_card_list
;
50 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
51 struct kmem_cache
*qeth_core_header_cache
;
52 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
54 static struct device
*qeth_core_root_dev
;
55 static unsigned int known_devices
[][10] = QETH_MODELLIST_ARRAY
;
56 static struct lock_class_key qdio_out_skb_queue_key
;
58 static void qeth_send_control_data_cb(struct qeth_channel
*,
59 struct qeth_cmd_buffer
*);
60 static int qeth_issue_next_read(struct qeth_card
*);
61 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
62 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
63 static void qeth_free_buffer_pool(struct qeth_card
*);
64 static int qeth_qdio_establish(struct qeth_card
*);
67 static inline void __qeth_fill_buffer_frag(struct sk_buff
*skb
,
68 struct qdio_buffer
*buffer
, int is_tso
,
69 int *next_element_to_fill
)
71 struct skb_frag_struct
*frag
;
74 int element
, cnt
, dlen
;
76 fragno
= skb_shinfo(skb
)->nr_frags
;
77 element
= *next_element_to_fill
;
81 buffer
->element
[element
].flags
=
82 SBAL_FLAGS_MIDDLE_FRAG
;
84 buffer
->element
[element
].flags
=
85 SBAL_FLAGS_FIRST_FRAG
;
86 dlen
= skb
->len
- skb
->data_len
;
88 buffer
->element
[element
].addr
= skb
->data
;
89 buffer
->element
[element
].length
= dlen
;
92 for (cnt
= 0; cnt
< fragno
; cnt
++) {
93 frag
= &skb_shinfo(skb
)->frags
[cnt
];
94 addr
= (page_to_pfn(frag
->page
) << PAGE_SHIFT
) +
96 buffer
->element
[element
].addr
= (char *)addr
;
97 buffer
->element
[element
].length
= frag
->size
;
98 if (cnt
< (fragno
- 1))
99 buffer
->element
[element
].flags
=
100 SBAL_FLAGS_MIDDLE_FRAG
;
102 buffer
->element
[element
].flags
=
103 SBAL_FLAGS_LAST_FRAG
;
106 *next_element_to_fill
= element
;
109 static inline const char *qeth_get_cardname(struct qeth_card
*card
)
111 if (card
->info
.guestlan
) {
112 switch (card
->info
.type
) {
113 case QETH_CARD_TYPE_OSAE
:
114 return " Guest LAN QDIO";
115 case QETH_CARD_TYPE_IQD
:
116 return " Guest LAN Hiper";
121 switch (card
->info
.type
) {
122 case QETH_CARD_TYPE_OSAE
:
123 return " OSD Express";
124 case QETH_CARD_TYPE_IQD
:
125 return " HiperSockets";
126 case QETH_CARD_TYPE_OSN
:
135 /* max length to be returned: 14 */
136 const char *qeth_get_cardname_short(struct qeth_card
*card
)
138 if (card
->info
.guestlan
) {
139 switch (card
->info
.type
) {
140 case QETH_CARD_TYPE_OSAE
:
141 return "GuestLAN QDIO";
142 case QETH_CARD_TYPE_IQD
:
143 return "GuestLAN Hiper";
148 switch (card
->info
.type
) {
149 case QETH_CARD_TYPE_OSAE
:
150 switch (card
->info
.link_type
) {
151 case QETH_LINK_TYPE_FAST_ETH
:
153 case QETH_LINK_TYPE_HSTR
:
155 case QETH_LINK_TYPE_GBIT_ETH
:
157 case QETH_LINK_TYPE_10GBIT_ETH
:
159 case QETH_LINK_TYPE_LANE_ETH100
:
160 return "OSD_FE_LANE";
161 case QETH_LINK_TYPE_LANE_TR
:
162 return "OSD_TR_LANE";
163 case QETH_LINK_TYPE_LANE_ETH1000
:
164 return "OSD_GbE_LANE";
165 case QETH_LINK_TYPE_LANE
:
166 return "OSD_ATM_LANE";
168 return "OSD_Express";
170 case QETH_CARD_TYPE_IQD
:
171 return "HiperSockets";
172 case QETH_CARD_TYPE_OSN
:
181 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
182 int clear_start_mask
)
186 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
187 card
->thread_allowed_mask
= threads
;
188 if (clear_start_mask
)
189 card
->thread_start_mask
&= threads
;
190 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
191 wake_up(&card
->wait_q
);
193 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
195 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
200 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
201 rc
= (card
->thread_running_mask
& threads
);
202 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
205 EXPORT_SYMBOL_GPL(qeth_threads_running
);
207 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
209 return wait_event_interruptible(card
->wait_q
,
210 qeth_threads_running(card
, threads
) == 0);
212 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
214 void qeth_clear_working_pool_list(struct qeth_card
*card
)
216 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
218 QETH_DBF_TEXT(TRACE
, 5, "clwrklst");
219 list_for_each_entry_safe(pool_entry
, tmp
,
220 &card
->qdio
.in_buf_pool
.entry_list
, list
){
221 list_del(&pool_entry
->list
);
224 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
226 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
228 struct qeth_buffer_pool_entry
*pool_entry
;
232 QETH_DBF_TEXT(TRACE
, 5, "alocpool");
233 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
234 pool_entry
= kmalloc(sizeof(*pool_entry
), GFP_KERNEL
);
236 qeth_free_buffer_pool(card
);
239 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
240 ptr
= (void *) __get_free_page(GFP_KERNEL
);
243 free_page((unsigned long)
244 pool_entry
->elements
[--j
]);
246 qeth_free_buffer_pool(card
);
249 pool_entry
->elements
[j
] = ptr
;
251 list_add(&pool_entry
->init_list
,
252 &card
->qdio
.init_pool
.entry_list
);
257 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
259 QETH_DBF_TEXT(TRACE
, 2, "realcbp");
261 if ((card
->state
!= CARD_STATE_DOWN
) &&
262 (card
->state
!= CARD_STATE_RECOVER
))
265 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
266 qeth_clear_working_pool_list(card
);
267 qeth_free_buffer_pool(card
);
268 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
269 card
->qdio
.init_pool
.buf_count
= bufcnt
;
270 return qeth_alloc_buffer_pool(card
);
273 int qeth_set_large_send(struct qeth_card
*card
,
274 enum qeth_large_send_types type
)
278 if (card
->dev
== NULL
) {
279 card
->options
.large_send
= type
;
282 if (card
->state
== CARD_STATE_UP
)
283 netif_tx_disable(card
->dev
);
284 card
->options
.large_send
= type
;
285 switch (card
->options
.large_send
) {
286 case QETH_LARGE_SEND_TSO
:
287 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
288 card
->dev
->features
|= NETIF_F_TSO
| NETIF_F_SG
|
291 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
293 card
->options
.large_send
= QETH_LARGE_SEND_NO
;
297 default: /* includes QETH_LARGE_SEND_NO */
298 card
->dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_SG
|
302 if (card
->state
== CARD_STATE_UP
)
303 netif_wake_queue(card
->dev
);
306 EXPORT_SYMBOL_GPL(qeth_set_large_send
);
308 static int qeth_issue_next_read(struct qeth_card
*card
)
311 struct qeth_cmd_buffer
*iob
;
313 QETH_DBF_TEXT(TRACE
, 5, "issnxrd");
314 if (card
->read
.state
!= CH_STATE_UP
)
316 iob
= qeth_get_buffer(&card
->read
);
318 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
319 "failed to recover an error on the device\n");
320 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
321 "available\n", dev_name(&card
->gdev
->dev
));
324 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
325 QETH_DBF_TEXT(TRACE
, 6, "noirqpnd");
326 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
329 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
330 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
331 atomic_set(&card
->read
.irq_pending
, 0);
332 qeth_schedule_recovery(card
);
333 wake_up(&card
->wait_q
);
338 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
340 struct qeth_reply
*reply
;
342 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
344 atomic_set(&reply
->refcnt
, 1);
345 atomic_set(&reply
->received
, 0);
351 static void qeth_get_reply(struct qeth_reply
*reply
)
353 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
354 atomic_inc(&reply
->refcnt
);
357 static void qeth_put_reply(struct qeth_reply
*reply
)
359 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
360 if (atomic_dec_and_test(&reply
->refcnt
))
364 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
365 struct qeth_card
*card
)
368 int com
= cmd
->hdr
.command
;
369 ipa_name
= qeth_get_ipa_cmd_name(com
);
371 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s returned x%X \"%s\"\n",
372 ipa_name
, com
, QETH_CARD_IFNAME(card
),
373 rc
, qeth_get_ipa_msg(rc
));
375 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s succeeded\n",
376 ipa_name
, com
, QETH_CARD_IFNAME(card
));
379 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
380 struct qeth_cmd_buffer
*iob
)
382 struct qeth_ipa_cmd
*cmd
= NULL
;
384 QETH_DBF_TEXT(TRACE
, 5, "chkipad");
385 if (IS_IPA(iob
->data
)) {
386 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
387 if (IS_IPA_REPLY(cmd
)) {
388 if (cmd
->hdr
.command
< IPA_CMD_SETCCID
||
389 cmd
->hdr
.command
> IPA_CMD_MODCCID
)
390 qeth_issue_ipa_msg(cmd
,
391 cmd
->hdr
.return_code
, card
);
394 switch (cmd
->hdr
.command
) {
395 case IPA_CMD_STOPLAN
:
396 dev_warn(&card
->gdev
->dev
,
397 "The link for interface %s on CHPID"
399 QETH_CARD_IFNAME(card
),
401 card
->lan_online
= 0;
402 if (card
->dev
&& netif_carrier_ok(card
->dev
))
403 netif_carrier_off(card
->dev
);
405 case IPA_CMD_STARTLAN
:
406 dev_info(&card
->gdev
->dev
,
407 "The link for %s on CHPID 0x%X has"
409 QETH_CARD_IFNAME(card
),
411 netif_carrier_on(card
->dev
);
412 card
->lan_online
= 1;
413 qeth_schedule_recovery(card
);
415 case IPA_CMD_MODCCID
:
417 case IPA_CMD_REGISTER_LOCAL_ADDR
:
418 QETH_DBF_TEXT(TRACE
, 3, "irla");
420 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
421 QETH_DBF_TEXT(TRACE
, 3, "urla");
424 QETH_DBF_MESSAGE(2, "Received data is IPA "
425 "but not a reply!\n");
433 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
435 struct qeth_reply
*reply
, *r
;
438 QETH_DBF_TEXT(TRACE
, 4, "clipalst");
440 spin_lock_irqsave(&card
->lock
, flags
);
441 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
442 qeth_get_reply(reply
);
444 atomic_inc(&reply
->received
);
445 list_del_init(&reply
->list
);
446 wake_up(&reply
->wait_q
);
447 qeth_put_reply(reply
);
449 spin_unlock_irqrestore(&card
->lock
, flags
);
451 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
453 static int qeth_check_idx_response(unsigned char *buffer
)
458 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
459 if ((buffer
[2] & 0xc0) == 0xc0) {
460 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
461 "with cause code 0x%02x%s\n",
463 ((buffer
[4] == 0x22) ?
464 " -- try another portname" : ""));
465 QETH_DBF_TEXT(TRACE
, 2, "ckidxres");
466 QETH_DBF_TEXT(TRACE
, 2, " idxterm");
467 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -EIO
);
473 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
476 struct qeth_card
*card
;
478 QETH_DBF_TEXT(TRACE
, 4, "setupccw");
479 card
= CARD_FROM_CDEV(channel
->ccwdev
);
480 if (channel
== &card
->read
)
481 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
483 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
484 channel
->ccw
.count
= len
;
485 channel
->ccw
.cda
= (__u32
) __pa(iob
);
488 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
492 QETH_DBF_TEXT(TRACE
, 6, "getbuff");
493 index
= channel
->io_buf_no
;
495 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
496 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
497 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
499 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
500 return channel
->iob
+ index
;
502 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
503 } while (index
!= channel
->io_buf_no
);
508 void qeth_release_buffer(struct qeth_channel
*channel
,
509 struct qeth_cmd_buffer
*iob
)
513 QETH_DBF_TEXT(TRACE
, 6, "relbuff");
514 spin_lock_irqsave(&channel
->iob_lock
, flags
);
515 memset(iob
->data
, 0, QETH_BUFSIZE
);
516 iob
->state
= BUF_STATE_FREE
;
517 iob
->callback
= qeth_send_control_data_cb
;
519 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
521 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
523 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
525 struct qeth_cmd_buffer
*buffer
= NULL
;
528 spin_lock_irqsave(&channel
->iob_lock
, flags
);
529 buffer
= __qeth_get_buffer(channel
);
530 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
534 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
536 struct qeth_cmd_buffer
*buffer
;
537 wait_event(channel
->wait_q
,
538 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
541 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
543 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
547 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
548 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
550 channel
->io_buf_no
= 0;
552 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
554 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
555 struct qeth_cmd_buffer
*iob
)
557 struct qeth_card
*card
;
558 struct qeth_reply
*reply
, *r
;
559 struct qeth_ipa_cmd
*cmd
;
563 QETH_DBF_TEXT(TRACE
, 4, "sndctlcb");
565 card
= CARD_FROM_CDEV(channel
->ccwdev
);
566 if (qeth_check_idx_response(iob
->data
)) {
567 qeth_clear_ipacmd_list(card
);
568 if (((iob
->data
[2] & 0xc0) == 0xc0) && iob
->data
[4] == 0xf6)
569 dev_err(&card
->gdev
->dev
,
570 "The qeth device is not configured "
571 "for the OSI layer required by z/VM\n");
572 qeth_schedule_recovery(card
);
576 cmd
= qeth_check_ipa_data(card
, iob
);
577 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
579 /*in case of OSN : check if cmd is set */
580 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
582 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
583 card
->osn_info
.assist_cb
!= NULL
) {
584 card
->osn_info
.assist_cb(card
->dev
, cmd
);
588 spin_lock_irqsave(&card
->lock
, flags
);
589 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
590 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
591 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
592 qeth_get_reply(reply
);
593 list_del_init(&reply
->list
);
594 spin_unlock_irqrestore(&card
->lock
, flags
);
596 if (reply
->callback
!= NULL
) {
598 reply
->offset
= (__u16
)((char *)cmd
-
600 keep_reply
= reply
->callback(card
,
604 keep_reply
= reply
->callback(card
,
609 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
613 spin_lock_irqsave(&card
->lock
, flags
);
614 list_add_tail(&reply
->list
,
615 &card
->cmd_waiter_list
);
616 spin_unlock_irqrestore(&card
->lock
, flags
);
618 atomic_inc(&reply
->received
);
619 wake_up(&reply
->wait_q
);
621 qeth_put_reply(reply
);
625 spin_unlock_irqrestore(&card
->lock
, flags
);
627 memcpy(&card
->seqno
.pdu_hdr_ack
,
628 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
630 qeth_release_buffer(channel
, iob
);
633 static int qeth_setup_channel(struct qeth_channel
*channel
)
637 QETH_DBF_TEXT(SETUP
, 2, "setupch");
638 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
639 channel
->iob
[cnt
].data
= (char *)
640 kmalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
641 if (channel
->iob
[cnt
].data
== NULL
)
643 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
644 channel
->iob
[cnt
].channel
= channel
;
645 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
646 channel
->iob
[cnt
].rc
= 0;
648 if (cnt
< QETH_CMD_BUFFER_NO
) {
650 kfree(channel
->iob
[cnt
].data
);
654 channel
->io_buf_no
= 0;
655 atomic_set(&channel
->irq_pending
, 0);
656 spin_lock_init(&channel
->iob_lock
);
658 init_waitqueue_head(&channel
->wait_q
);
662 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
663 unsigned long thread
)
667 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
668 if (!(card
->thread_allowed_mask
& thread
) ||
669 (card
->thread_start_mask
& thread
)) {
670 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
673 card
->thread_start_mask
|= thread
;
674 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
678 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
682 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
683 card
->thread_start_mask
&= ~thread
;
684 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
685 wake_up(&card
->wait_q
);
687 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
689 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
693 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
694 card
->thread_running_mask
&= ~thread
;
695 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
696 wake_up(&card
->wait_q
);
698 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
700 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
705 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
706 if (card
->thread_start_mask
& thread
) {
707 if ((card
->thread_allowed_mask
& thread
) &&
708 !(card
->thread_running_mask
& thread
)) {
710 card
->thread_start_mask
&= ~thread
;
711 card
->thread_running_mask
|= thread
;
715 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
719 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
723 wait_event(card
->wait_q
,
724 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
727 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
729 void qeth_schedule_recovery(struct qeth_card
*card
)
731 QETH_DBF_TEXT(TRACE
, 2, "startrec");
732 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
733 schedule_work(&card
->kernel_thread_starter
);
735 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
737 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
742 sense
= (char *) irb
->ecw
;
743 cstat
= irb
->scsw
.cmd
.cstat
;
744 dstat
= irb
->scsw
.cmd
.dstat
;
746 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
747 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
748 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
749 QETH_DBF_TEXT(TRACE
, 2, "CGENCHK");
750 dev_warn(&cdev
->dev
, "The qeth device driver "
751 "failed to recover an error on the device\n");
752 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x ",
753 dev_name(&cdev
->dev
), dstat
, cstat
);
754 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
759 if (dstat
& DEV_STAT_UNIT_CHECK
) {
760 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
761 SENSE_RESETTING_EVENT_FLAG
) {
762 QETH_DBF_TEXT(TRACE
, 2, "REVIND");
765 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
766 SENSE_COMMAND_REJECT_FLAG
) {
767 QETH_DBF_TEXT(TRACE
, 2, "CMDREJi");
770 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
771 QETH_DBF_TEXT(TRACE
, 2, "AFFE");
774 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
775 QETH_DBF_TEXT(TRACE
, 2, "ZEROSEN");
778 QETH_DBF_TEXT(TRACE
, 2, "DGENCHK");
784 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
785 unsigned long intparm
, struct irb
*irb
)
790 switch (PTR_ERR(irb
)) {
792 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
793 dev_name(&cdev
->dev
));
794 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
795 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -EIO
);
798 dev_warn(&cdev
->dev
, "A hardware operation timed out"
800 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
801 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -ETIMEDOUT
);
802 if (intparm
== QETH_RCD_PARM
) {
803 struct qeth_card
*card
= CARD_FROM_CDEV(cdev
);
805 if (card
&& (card
->data
.ccwdev
== cdev
)) {
806 card
->data
.state
= CH_STATE_DOWN
;
807 wake_up(&card
->wait_q
);
812 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
813 dev_name(&cdev
->dev
), PTR_ERR(irb
));
814 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
815 QETH_DBF_TEXT(TRACE
, 2, " rc???");
820 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
825 struct qeth_cmd_buffer
*buffer
;
826 struct qeth_channel
*channel
;
827 struct qeth_card
*card
;
828 struct qeth_cmd_buffer
*iob
;
831 QETH_DBF_TEXT(TRACE
, 5, "irq");
833 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
835 cstat
= irb
->scsw
.cmd
.cstat
;
836 dstat
= irb
->scsw
.cmd
.dstat
;
838 card
= CARD_FROM_CDEV(cdev
);
842 if (card
->read
.ccwdev
== cdev
) {
843 channel
= &card
->read
;
844 QETH_DBF_TEXT(TRACE
, 5, "read");
845 } else if (card
->write
.ccwdev
== cdev
) {
846 channel
= &card
->write
;
847 QETH_DBF_TEXT(TRACE
, 5, "write");
849 channel
= &card
->data
;
850 QETH_DBF_TEXT(TRACE
, 5, "data");
852 atomic_set(&channel
->irq_pending
, 0);
854 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
855 channel
->state
= CH_STATE_STOPPED
;
857 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
858 channel
->state
= CH_STATE_HALTED
;
860 /*let's wake up immediately on data channel*/
861 if ((channel
== &card
->data
) && (intparm
!= 0) &&
862 (intparm
!= QETH_RCD_PARM
))
865 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
866 QETH_DBF_TEXT(TRACE
, 6, "clrchpar");
867 /* we don't have to handle this further */
870 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
871 QETH_DBF_TEXT(TRACE
, 6, "hltchpar");
872 /* we don't have to handle this further */
875 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
876 (dstat
& DEV_STAT_UNIT_CHECK
) ||
878 if (irb
->esw
.esw0
.erw
.cons
) {
879 dev_warn(&channel
->ccwdev
->dev
,
880 "The qeth device driver failed to recover "
881 "an error on the device\n");
882 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
884 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
885 print_hex_dump(KERN_WARNING
, "qeth: irb ",
886 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
887 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
888 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
890 if (intparm
== QETH_RCD_PARM
) {
891 channel
->state
= CH_STATE_DOWN
;
894 rc
= qeth_get_problem(cdev
, irb
);
896 qeth_clear_ipacmd_list(card
);
897 qeth_schedule_recovery(card
);
902 if (intparm
== QETH_RCD_PARM
) {
903 channel
->state
= CH_STATE_RCD_DONE
;
907 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
908 buffer
->state
= BUF_STATE_PROCESSED
;
910 if (channel
== &card
->data
)
912 if (channel
== &card
->read
&&
913 channel
->state
== CH_STATE_UP
)
914 qeth_issue_next_read(card
);
917 index
= channel
->buf_no
;
918 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
919 if (iob
[index
].callback
!= NULL
)
920 iob
[index
].callback(channel
, iob
+ index
);
922 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
924 channel
->buf_no
= index
;
926 wake_up(&card
->wait_q
);
930 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
931 struct qeth_qdio_out_buffer
*buf
)
936 /* is PCI flag set on buffer? */
937 if (buf
->buffer
->element
[0].flags
& 0x40)
938 atomic_dec(&queue
->set_pci_flags_count
);
940 skb
= skb_dequeue(&buf
->skb_list
);
942 atomic_dec(&skb
->users
);
943 dev_kfree_skb_any(skb
);
944 skb
= skb_dequeue(&buf
->skb_list
);
946 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
947 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
948 kmem_cache_free(qeth_core_header_cache
,
949 buf
->buffer
->element
[i
].addr
);
950 buf
->is_header
[i
] = 0;
951 buf
->buffer
->element
[i
].length
= 0;
952 buf
->buffer
->element
[i
].addr
= NULL
;
953 buf
->buffer
->element
[i
].flags
= 0;
955 buf
->next_element_to_fill
= 0;
956 atomic_set(&buf
->state
, QETH_QDIO_BUF_EMPTY
);
959 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
963 QETH_DBF_TEXT(TRACE
, 2, "clearqdbf");
964 /* clear outbound buffers to free skbs */
965 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
966 if (card
->qdio
.out_qs
[i
]) {
967 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
)
968 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
969 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
972 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
974 static void qeth_free_buffer_pool(struct qeth_card
*card
)
976 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
978 QETH_DBF_TEXT(TRACE
, 5, "freepool");
979 list_for_each_entry_safe(pool_entry
, tmp
,
980 &card
->qdio
.init_pool
.entry_list
, init_list
){
981 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
982 free_page((unsigned long)pool_entry
->elements
[i
]);
983 list_del(&pool_entry
->init_list
);
988 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
992 QETH_DBF_TEXT(TRACE
, 2, "freeqdbf");
993 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
994 QETH_QDIO_UNINITIALIZED
)
996 kfree(card
->qdio
.in_q
);
997 card
->qdio
.in_q
= NULL
;
998 /* inbound buffer pool */
999 qeth_free_buffer_pool(card
);
1000 /* free outbound qdio_qs */
1001 if (card
->qdio
.out_qs
) {
1002 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1003 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
)
1004 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
1005 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
1006 kfree(card
->qdio
.out_qs
[i
]);
1008 kfree(card
->qdio
.out_qs
);
1009 card
->qdio
.out_qs
= NULL
;
1013 static void qeth_clean_channel(struct qeth_channel
*channel
)
1017 QETH_DBF_TEXT(SETUP
, 2, "freech");
1018 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1019 kfree(channel
->iob
[cnt
].data
);
1022 static int qeth_is_1920_device(struct qeth_card
*card
)
1024 int single_queue
= 0;
1025 struct ccw_device
*ccwdev
;
1026 struct channelPath_dsc
{
1037 QETH_DBF_TEXT(SETUP
, 2, "chk_1920");
1039 ccwdev
= card
->data
.ccwdev
;
1040 chp_dsc
= (struct channelPath_dsc
*)ccw_device_get_chp_desc(ccwdev
, 0);
1041 if (chp_dsc
!= NULL
) {
1042 /* CHPP field bit 6 == 1 -> single queue */
1043 single_queue
= ((chp_dsc
->chpp
& 0x02) == 0x02);
1046 QETH_DBF_TEXT_(SETUP
, 2, "rc:%x", single_queue
);
1047 return single_queue
;
1050 static void qeth_init_qdio_info(struct qeth_card
*card
)
1052 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1053 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1055 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1056 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1057 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1058 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1059 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1062 static void qeth_set_intial_options(struct qeth_card
*card
)
1064 card
->options
.route4
.type
= NO_ROUTER
;
1065 card
->options
.route6
.type
= NO_ROUTER
;
1066 card
->options
.checksum_type
= QETH_CHECKSUM_DEFAULT
;
1067 card
->options
.broadcast_mode
= QETH_TR_BROADCAST_ALLRINGS
;
1068 card
->options
.macaddr_mode
= QETH_TR_MACADDR_NONCANONICAL
;
1069 card
->options
.fake_broadcast
= 0;
1070 card
->options
.add_hhlen
= DEFAULT_ADD_HHLEN
;
1071 card
->options
.performance_stats
= 0;
1072 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1075 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1077 unsigned long flags
;
1080 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1081 QETH_DBF_TEXT_(TRACE
, 4, " %02x%02x%02x",
1082 (u8
) card
->thread_start_mask
,
1083 (u8
) card
->thread_allowed_mask
,
1084 (u8
) card
->thread_running_mask
);
1085 rc
= (card
->thread_start_mask
& thread
);
1086 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1090 static void qeth_start_kernel_thread(struct work_struct
*work
)
1092 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1093 kernel_thread_starter
);
1094 QETH_DBF_TEXT(TRACE
, 2, "strthrd");
1096 if (card
->read
.state
!= CH_STATE_UP
&&
1097 card
->write
.state
!= CH_STATE_UP
)
1099 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
))
1100 kthread_run(card
->discipline
.recover
, (void *) card
,
1104 static int qeth_setup_card(struct qeth_card
*card
)
1107 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1108 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1110 card
->read
.state
= CH_STATE_DOWN
;
1111 card
->write
.state
= CH_STATE_DOWN
;
1112 card
->data
.state
= CH_STATE_DOWN
;
1113 card
->state
= CARD_STATE_DOWN
;
1114 card
->lan_online
= 0;
1115 card
->use_hard_stop
= 0;
1117 spin_lock_init(&card
->vlanlock
);
1118 spin_lock_init(&card
->mclock
);
1119 card
->vlangrp
= NULL
;
1120 spin_lock_init(&card
->lock
);
1121 spin_lock_init(&card
->ip_lock
);
1122 spin_lock_init(&card
->thread_mask_lock
);
1123 card
->thread_start_mask
= 0;
1124 card
->thread_allowed_mask
= 0;
1125 card
->thread_running_mask
= 0;
1126 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1127 INIT_LIST_HEAD(&card
->ip_list
);
1128 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1129 if (!card
->ip_tbd_list
) {
1130 QETH_DBF_TEXT(SETUP
, 0, "iptbdnom");
1133 INIT_LIST_HEAD(card
->ip_tbd_list
);
1134 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1135 init_waitqueue_head(&card
->wait_q
);
1136 /* intial options */
1137 qeth_set_intial_options(card
);
1138 /* IP address takeover */
1139 INIT_LIST_HEAD(&card
->ipato
.entries
);
1140 card
->ipato
.enabled
= 0;
1141 card
->ipato
.invert4
= 0;
1142 card
->ipato
.invert6
= 0;
1143 /* init QDIO stuff */
1144 qeth_init_qdio_info(card
);
1148 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1150 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1151 qeth_service_level
);
1152 seq_printf(m
, "qeth: %s firmware level %s\n", CARD_BUS_ID(card
),
1153 card
->info
.mcl_level
);
1156 static struct qeth_card
*qeth_alloc_card(void)
1158 struct qeth_card
*card
;
1160 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1161 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1164 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1165 if (qeth_setup_channel(&card
->read
)) {
1169 if (qeth_setup_channel(&card
->write
)) {
1170 qeth_clean_channel(&card
->read
);
1174 card
->options
.layer2
= -1;
1175 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1176 register_service_level(&card
->qeth_service_level
);
1180 static int qeth_determine_card_type(struct qeth_card
*card
)
1184 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1186 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1187 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1188 while (known_devices
[i
][4]) {
1189 if ((CARD_RDEV(card
)->id
.dev_type
== known_devices
[i
][2]) &&
1190 (CARD_RDEV(card
)->id
.dev_model
== known_devices
[i
][3])) {
1191 card
->info
.type
= known_devices
[i
][4];
1192 card
->qdio
.no_out_queues
= known_devices
[i
][8];
1193 card
->info
.is_multicast_different
= known_devices
[i
][9];
1194 if (qeth_is_1920_device(card
)) {
1195 dev_info(&card
->gdev
->dev
,
1196 "Priority Queueing not supported\n");
1197 card
->qdio
.no_out_queues
= 1;
1198 card
->qdio
.default_out_queue
= 0;
1204 card
->info
.type
= QETH_CARD_TYPE_UNKNOWN
;
1205 dev_err(&card
->gdev
->dev
, "The adapter hardware is of an "
1210 static int qeth_clear_channel(struct qeth_channel
*channel
)
1212 unsigned long flags
;
1213 struct qeth_card
*card
;
1216 QETH_DBF_TEXT(TRACE
, 3, "clearch");
1217 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1218 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1219 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1220 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1224 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1225 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1226 if (rc
== -ERESTARTSYS
)
1228 if (channel
->state
!= CH_STATE_STOPPED
)
1230 channel
->state
= CH_STATE_DOWN
;
1234 static int qeth_halt_channel(struct qeth_channel
*channel
)
1236 unsigned long flags
;
1237 struct qeth_card
*card
;
1240 QETH_DBF_TEXT(TRACE
, 3, "haltch");
1241 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1242 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1243 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1244 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1248 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1249 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1250 if (rc
== -ERESTARTSYS
)
1252 if (channel
->state
!= CH_STATE_HALTED
)
1257 static int qeth_halt_channels(struct qeth_card
*card
)
1259 int rc1
= 0, rc2
= 0, rc3
= 0;
1261 QETH_DBF_TEXT(TRACE
, 3, "haltchs");
1262 rc1
= qeth_halt_channel(&card
->read
);
1263 rc2
= qeth_halt_channel(&card
->write
);
1264 rc3
= qeth_halt_channel(&card
->data
);
1272 static int qeth_clear_channels(struct qeth_card
*card
)
1274 int rc1
= 0, rc2
= 0, rc3
= 0;
1276 QETH_DBF_TEXT(TRACE
, 3, "clearchs");
1277 rc1
= qeth_clear_channel(&card
->read
);
1278 rc2
= qeth_clear_channel(&card
->write
);
1279 rc3
= qeth_clear_channel(&card
->data
);
1287 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1291 QETH_DBF_TEXT(TRACE
, 3, "clhacrd");
1292 QETH_DBF_HEX(TRACE
, 3, &card
, sizeof(void *));
1295 rc
= qeth_halt_channels(card
);
1298 return qeth_clear_channels(card
);
1301 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1305 QETH_DBF_TEXT(TRACE
, 3, "qdioclr");
1306 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1307 QETH_QDIO_CLEANING
)) {
1308 case QETH_QDIO_ESTABLISHED
:
1309 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1310 rc
= qdio_cleanup(CARD_DDEV(card
),
1311 QDIO_FLAG_CLEANUP_USING_HALT
);
1313 rc
= qdio_cleanup(CARD_DDEV(card
),
1314 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1316 QETH_DBF_TEXT_(TRACE
, 3, "1err%d", rc
);
1317 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1319 case QETH_QDIO_CLEANING
:
1324 rc
= qeth_clear_halt_card(card
, use_halt
);
1326 QETH_DBF_TEXT_(TRACE
, 3, "2err%d", rc
);
1327 card
->state
= CARD_STATE_DOWN
;
1330 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1332 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1338 struct qeth_channel
*channel
= &card
->data
;
1339 unsigned long flags
;
1342 * scan for RCD command in extended SenseID data
1344 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1345 if (!ciw
|| ciw
->cmd
== 0)
1347 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1351 channel
->ccw
.cmd_code
= ciw
->cmd
;
1352 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1353 channel
->ccw
.count
= ciw
->count
;
1354 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1355 channel
->state
= CH_STATE_RCD
;
1356 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1357 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1358 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1360 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1362 wait_event(card
->wait_q
,
1363 (channel
->state
== CH_STATE_RCD_DONE
||
1364 channel
->state
== CH_STATE_DOWN
));
1365 if (channel
->state
== CH_STATE_DOWN
)
1368 channel
->state
= CH_STATE_DOWN
;
1374 *length
= ciw
->count
;
1380 static int qeth_get_unitaddr(struct qeth_card
*card
)
1386 QETH_DBF_TEXT(SETUP
, 2, "getunit");
1387 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
1389 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
1390 dev_name(&card
->gdev
->dev
), rc
);
1393 card
->info
.chpid
= prcd
[30];
1394 card
->info
.unit_addr2
= prcd
[31];
1395 card
->info
.cula
= prcd
[63];
1396 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1397 (prcd
[0x11] == _ascebc
['M']));
1402 static void qeth_init_tokens(struct qeth_card
*card
)
1404 card
->token
.issuer_rm_w
= 0x00010103UL
;
1405 card
->token
.cm_filter_w
= 0x00010108UL
;
1406 card
->token
.cm_connection_w
= 0x0001010aUL
;
1407 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1408 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1411 static void qeth_init_func_level(struct qeth_card
*card
)
1413 if (card
->ipato
.enabled
) {
1414 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1415 card
->info
.func_level
=
1416 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT
;
1418 card
->info
.func_level
=
1419 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT
;
1421 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1422 /*FIXME:why do we have same values for dis and ena for
1424 card
->info
.func_level
=
1425 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT
;
1427 card
->info
.func_level
=
1428 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT
;
1432 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1433 void (*idx_reply_cb
)(struct qeth_channel
*,
1434 struct qeth_cmd_buffer
*))
1436 struct qeth_cmd_buffer
*iob
;
1437 unsigned long flags
;
1439 struct qeth_card
*card
;
1441 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1442 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1443 iob
= qeth_get_buffer(channel
);
1444 iob
->callback
= idx_reply_cb
;
1445 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1446 channel
->ccw
.count
= QETH_BUFSIZE
;
1447 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1449 wait_event(card
->wait_q
,
1450 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1451 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1452 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1453 rc
= ccw_device_start(channel
->ccwdev
,
1454 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1455 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1458 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1459 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1460 atomic_set(&channel
->irq_pending
, 0);
1461 wake_up(&card
->wait_q
);
1464 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1465 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1466 if (rc
== -ERESTARTSYS
)
1468 if (channel
->state
!= CH_STATE_UP
) {
1470 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1471 qeth_clear_cmd_buffers(channel
);
1477 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1478 void (*idx_reply_cb
)(struct qeth_channel
*,
1479 struct qeth_cmd_buffer
*))
1481 struct qeth_card
*card
;
1482 struct qeth_cmd_buffer
*iob
;
1483 unsigned long flags
;
1487 struct ccw_dev_id temp_devid
;
1489 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1491 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1493 iob
= qeth_get_buffer(channel
);
1494 iob
->callback
= idx_reply_cb
;
1495 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1496 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1497 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1498 if (channel
== &card
->write
) {
1499 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1500 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1501 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1502 card
->seqno
.trans_hdr
++;
1504 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1505 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1506 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1508 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1509 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1510 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1511 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1512 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1513 &card
->info
.func_level
, sizeof(__u16
));
1514 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1515 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1516 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1517 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1519 wait_event(card
->wait_q
,
1520 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1521 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1522 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1523 rc
= ccw_device_start(channel
->ccwdev
,
1524 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1525 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1528 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1530 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1531 atomic_set(&channel
->irq_pending
, 0);
1532 wake_up(&card
->wait_q
);
1535 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1536 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1537 if (rc
== -ERESTARTSYS
)
1539 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1540 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1541 " failed to recover an error on the device\n");
1542 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1543 dev_name(&channel
->ccwdev
->dev
));
1544 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1545 qeth_clear_cmd_buffers(channel
);
1548 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1551 static int qeth_peer_func_level(int level
)
1553 if ((level
& 0xff) == 8)
1554 return (level
& 0xff) + 0x400;
1555 if (((level
>> 8) & 3) == 1)
1556 return (level
& 0xff) + 0x200;
1560 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1561 struct qeth_cmd_buffer
*iob
)
1563 struct qeth_card
*card
;
1566 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1568 if (channel
->state
== CH_STATE_DOWN
) {
1569 channel
->state
= CH_STATE_ACTIVATING
;
1572 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1574 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1575 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == 0x19)
1576 dev_err(&card
->write
.ccwdev
->dev
,
1577 "The adapter is used exclusively by another "
1580 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1581 " negative reply\n",
1582 dev_name(&card
->write
.ccwdev
->dev
));
1585 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1586 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
1587 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1588 "function level mismatch (sent: 0x%x, received: "
1589 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
1590 card
->info
.func_level
, temp
);
1593 channel
->state
= CH_STATE_UP
;
1595 qeth_release_buffer(channel
, iob
);
1598 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
1599 struct qeth_cmd_buffer
*iob
)
1601 struct qeth_card
*card
;
1604 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
1605 if (channel
->state
== CH_STATE_DOWN
) {
1606 channel
->state
= CH_STATE_ACTIVATING
;
1610 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1611 if (qeth_check_idx_response(iob
->data
))
1614 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1615 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == 0x19)
1616 dev_err(&card
->write
.ccwdev
->dev
,
1617 "The adapter is used exclusively by another "
1620 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1621 " negative reply\n",
1622 dev_name(&card
->read
.ccwdev
->dev
));
1627 * temporary fix for microcode bug
1628 * to revert it,replace OR by AND
1630 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob
->data
)) ||
1631 (card
->info
.type
== QETH_CARD_TYPE_OSAE
))
1632 card
->info
.portname_required
= 1;
1634 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1635 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
1636 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1637 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1638 dev_name(&card
->read
.ccwdev
->dev
),
1639 card
->info
.func_level
, temp
);
1642 memcpy(&card
->token
.issuer_rm_r
,
1643 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1644 QETH_MPC_TOKEN_LENGTH
);
1645 memcpy(&card
->info
.mcl_level
[0],
1646 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
1647 channel
->state
= CH_STATE_UP
;
1649 qeth_release_buffer(channel
, iob
);
1652 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
1653 struct qeth_cmd_buffer
*iob
)
1655 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
1656 iob
->callback
= qeth_release_buffer
;
1658 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1659 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1660 card
->seqno
.trans_hdr
++;
1661 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
1662 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
1663 card
->seqno
.pdu_hdr
++;
1664 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
1665 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
1666 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1668 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
1670 int qeth_send_control_data(struct qeth_card
*card
, int len
,
1671 struct qeth_cmd_buffer
*iob
,
1672 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1677 unsigned long flags
;
1678 struct qeth_reply
*reply
= NULL
;
1679 unsigned long timeout
, event_timeout
;
1680 struct qeth_ipa_cmd
*cmd
;
1682 QETH_DBF_TEXT(TRACE
, 2, "sendctl");
1684 reply
= qeth_alloc_reply(card
);
1688 reply
->callback
= reply_cb
;
1689 reply
->param
= reply_param
;
1690 if (card
->state
== CARD_STATE_DOWN
)
1691 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
1693 reply
->seqno
= card
->seqno
.ipa
++;
1694 init_waitqueue_head(&reply
->wait_q
);
1695 spin_lock_irqsave(&card
->lock
, flags
);
1696 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
1697 spin_unlock_irqrestore(&card
->lock
, flags
);
1698 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1700 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
1701 qeth_prepare_control_data(card
, len
, iob
);
1703 if (IS_IPA(iob
->data
))
1704 event_timeout
= QETH_IPA_TIMEOUT
;
1706 event_timeout
= QETH_TIMEOUT
;
1707 timeout
= jiffies
+ event_timeout
;
1709 QETH_DBF_TEXT(TRACE
, 6, "noirqpnd");
1710 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1711 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
1712 (addr_t
) iob
, 0, 0);
1713 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1715 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
1716 "ccw_device_start rc = %i\n",
1717 dev_name(&card
->write
.ccwdev
->dev
), rc
);
1718 QETH_DBF_TEXT_(TRACE
, 2, " err%d", rc
);
1719 spin_lock_irqsave(&card
->lock
, flags
);
1720 list_del_init(&reply
->list
);
1721 qeth_put_reply(reply
);
1722 spin_unlock_irqrestore(&card
->lock
, flags
);
1723 qeth_release_buffer(iob
->channel
, iob
);
1724 atomic_set(&card
->write
.irq_pending
, 0);
1725 wake_up(&card
->wait_q
);
1729 /* we have only one long running ipassist, since we can ensure
1730 process context of this command we can sleep */
1731 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1732 if ((cmd
->hdr
.command
== IPA_CMD_SETIP
) &&
1733 (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)) {
1734 if (!wait_event_timeout(reply
->wait_q
,
1735 atomic_read(&reply
->received
), event_timeout
))
1738 while (!atomic_read(&reply
->received
)) {
1739 if (time_after(jiffies
, timeout
))
1746 qeth_put_reply(reply
);
1750 spin_lock_irqsave(&reply
->card
->lock
, flags
);
1751 list_del_init(&reply
->list
);
1752 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
1754 atomic_inc(&reply
->received
);
1755 wake_up(&reply
->wait_q
);
1757 qeth_put_reply(reply
);
1760 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
1762 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1765 struct qeth_cmd_buffer
*iob
;
1767 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
1769 iob
= (struct qeth_cmd_buffer
*) data
;
1770 memcpy(&card
->token
.cm_filter_r
,
1771 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
1772 QETH_MPC_TOKEN_LENGTH
);
1773 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1777 static int qeth_cm_enable(struct qeth_card
*card
)
1780 struct qeth_cmd_buffer
*iob
;
1782 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
1784 iob
= qeth_wait_for_buffer(&card
->write
);
1785 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
1786 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
1787 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
1788 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
1789 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
1791 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
1792 qeth_cm_enable_cb
, NULL
);
1796 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1800 struct qeth_cmd_buffer
*iob
;
1802 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
1804 iob
= (struct qeth_cmd_buffer
*) data
;
1805 memcpy(&card
->token
.cm_connection_r
,
1806 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
1807 QETH_MPC_TOKEN_LENGTH
);
1808 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1812 static int qeth_cm_setup(struct qeth_card
*card
)
1815 struct qeth_cmd_buffer
*iob
;
1817 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
1819 iob
= qeth_wait_for_buffer(&card
->write
);
1820 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
1821 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
1822 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
1823 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
1824 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
1825 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
1826 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
1827 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
1828 qeth_cm_setup_cb
, NULL
);
1833 static inline int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
1835 switch (card
->info
.type
) {
1836 case QETH_CARD_TYPE_UNKNOWN
:
1838 case QETH_CARD_TYPE_IQD
:
1839 return card
->info
.max_mtu
;
1840 case QETH_CARD_TYPE_OSAE
:
1841 switch (card
->info
.link_type
) {
1842 case QETH_LINK_TYPE_HSTR
:
1843 case QETH_LINK_TYPE_LANE_TR
:
1853 static inline int qeth_get_max_mtu_for_card(int cardtype
)
1857 case QETH_CARD_TYPE_UNKNOWN
:
1858 case QETH_CARD_TYPE_OSAE
:
1859 case QETH_CARD_TYPE_OSN
:
1861 case QETH_CARD_TYPE_IQD
:
1868 static inline int qeth_get_mtu_out_of_mpc(int cardtype
)
1871 case QETH_CARD_TYPE_IQD
:
1878 static inline int qeth_get_mtu_outof_framesize(int framesize
)
1880 switch (framesize
) {
1894 static inline int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
1896 switch (card
->info
.type
) {
1897 case QETH_CARD_TYPE_OSAE
:
1898 return ((mtu
>= 576) && (mtu
<= 61440));
1899 case QETH_CARD_TYPE_IQD
:
1900 return ((mtu
>= 576) &&
1901 (mtu
<= card
->info
.max_mtu
+ 4096 - 32));
1902 case QETH_CARD_TYPE_OSN
:
1903 case QETH_CARD_TYPE_UNKNOWN
:
1909 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1913 __u16 mtu
, framesize
;
1916 struct qeth_cmd_buffer
*iob
;
1918 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
1920 iob
= (struct qeth_cmd_buffer
*) data
;
1921 memcpy(&card
->token
.ulp_filter_r
,
1922 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
1923 QETH_MPC_TOKEN_LENGTH
);
1924 if (qeth_get_mtu_out_of_mpc(card
->info
.type
)) {
1925 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
1926 mtu
= qeth_get_mtu_outof_framesize(framesize
);
1929 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1932 card
->info
.max_mtu
= mtu
;
1933 card
->info
.initial_mtu
= mtu
;
1934 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
1936 card
->info
.initial_mtu
= qeth_get_initial_mtu_for_card(card
);
1937 card
->info
.max_mtu
= qeth_get_max_mtu_for_card(card
->info
.type
);
1938 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1941 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
1942 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
1944 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
1945 card
->info
.link_type
= link_type
;
1947 card
->info
.link_type
= 0;
1948 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1952 static int qeth_ulp_enable(struct qeth_card
*card
)
1956 struct qeth_cmd_buffer
*iob
;
1958 /*FIXME: trace view callbacks*/
1959 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
1961 iob
= qeth_wait_for_buffer(&card
->write
);
1962 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
1964 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
1965 (__u8
) card
->info
.portno
;
1966 if (card
->options
.layer2
)
1967 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
1968 prot_type
= QETH_PROT_OSN2
;
1970 prot_type
= QETH_PROT_LAYER2
;
1972 prot_type
= QETH_PROT_TCPIP
;
1974 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
1975 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
1976 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
1977 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
1978 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
1979 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob
->data
),
1980 card
->info
.portname
, 9);
1981 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
1982 qeth_ulp_enable_cb
, NULL
);
1987 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1990 struct qeth_cmd_buffer
*iob
;
1992 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
1994 iob
= (struct qeth_cmd_buffer
*) data
;
1995 memcpy(&card
->token
.ulp_connection_r
,
1996 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
1997 QETH_MPC_TOKEN_LENGTH
);
1998 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2002 static int qeth_ulp_setup(struct qeth_card
*card
)
2006 struct qeth_cmd_buffer
*iob
;
2007 struct ccw_dev_id dev_id
;
2009 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2011 iob
= qeth_wait_for_buffer(&card
->write
);
2012 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2014 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2015 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2016 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2017 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2018 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2019 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2021 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2022 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2023 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2024 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2025 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2026 qeth_ulp_setup_cb
, NULL
);
2030 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2034 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2036 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2037 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2040 card
->qdio
.in_q
= kmalloc(sizeof(struct qeth_qdio_q
),
2042 if (!card
->qdio
.in_q
)
2044 QETH_DBF_TEXT(SETUP
, 2, "inq");
2045 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.in_q
, sizeof(void *));
2046 memset(card
->qdio
.in_q
, 0, sizeof(struct qeth_qdio_q
));
2047 /* give inbound qeth_qdio_buffers their qdio_buffers */
2048 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
2049 card
->qdio
.in_q
->bufs
[i
].buffer
=
2050 &card
->qdio
.in_q
->qdio_bufs
[i
];
2051 /* inbound buffer pool */
2052 if (qeth_alloc_buffer_pool(card
))
2056 kmalloc(card
->qdio
.no_out_queues
*
2057 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2058 if (!card
->qdio
.out_qs
)
2060 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2061 card
->qdio
.out_qs
[i
] = kmalloc(sizeof(struct qeth_qdio_out_q
),
2063 if (!card
->qdio
.out_qs
[i
])
2065 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2066 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2067 memset(card
->qdio
.out_qs
[i
], 0, sizeof(struct qeth_qdio_out_q
));
2068 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2069 /* give outbound qeth_qdio_buffers their qdio_buffers */
2070 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2071 card
->qdio
.out_qs
[i
]->bufs
[j
].buffer
=
2072 &card
->qdio
.out_qs
[i
]->qdio_bufs
[j
];
2073 skb_queue_head_init(&card
->qdio
.out_qs
[i
]->bufs
[j
].
2076 &card
->qdio
.out_qs
[i
]->bufs
[j
].skb_list
.lock
,
2077 &qdio_out_skb_queue_key
);
2078 INIT_LIST_HEAD(&card
->qdio
.out_qs
[i
]->bufs
[j
].ctx_list
);
2085 kfree(card
->qdio
.out_qs
[--i
]);
2086 kfree(card
->qdio
.out_qs
);
2087 card
->qdio
.out_qs
= NULL
;
2089 qeth_free_buffer_pool(card
);
2091 kfree(card
->qdio
.in_q
);
2092 card
->qdio
.in_q
= NULL
;
2094 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2098 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2102 param_field
[0] = _ascebc
['P'];
2103 param_field
[1] = _ascebc
['C'];
2104 param_field
[2] = _ascebc
['I'];
2105 param_field
[3] = _ascebc
['T'];
2106 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2107 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2108 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2111 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2114 param_field
[16] = _ascebc
['B'];
2115 param_field
[17] = _ascebc
['L'];
2116 param_field
[18] = _ascebc
['K'];
2117 param_field
[19] = _ascebc
['T'];
2118 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2119 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2120 *((unsigned int *) (¶m_field
[28])) =
2121 card
->info
.blkt
.inter_packet_jumbo
;
2124 static int qeth_qdio_activate(struct qeth_card
*card
)
2126 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2127 return qdio_activate(CARD_DDEV(card
));
2130 static int qeth_dm_act(struct qeth_card
*card
)
2133 struct qeth_cmd_buffer
*iob
;
2135 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2137 iob
= qeth_wait_for_buffer(&card
->write
);
2138 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2140 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2141 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2142 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2143 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2144 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2148 static int qeth_mpc_initialize(struct qeth_card
*card
)
2152 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2154 rc
= qeth_issue_next_read(card
);
2156 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2159 rc
= qeth_cm_enable(card
);
2161 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2164 rc
= qeth_cm_setup(card
);
2166 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2169 rc
= qeth_ulp_enable(card
);
2171 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2174 rc
= qeth_ulp_setup(card
);
2176 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2179 rc
= qeth_alloc_qdio_buffers(card
);
2181 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2184 rc
= qeth_qdio_establish(card
);
2186 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2187 qeth_free_qdio_buffers(card
);
2190 rc
= qeth_qdio_activate(card
);
2192 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2195 rc
= qeth_dm_act(card
);
2197 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2203 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2207 static void qeth_print_status_with_portname(struct qeth_card
*card
)
2212 sprintf(dbf_text
, "%s", card
->info
.portname
+ 1);
2213 for (i
= 0; i
< 8; i
++)
2215 (char) _ebcasc
[(__u8
) dbf_text
[i
]];
2217 dev_info(&card
->gdev
->dev
, "Device is a%s card%s%s%s\n"
2218 "with link type %s (portname: %s)\n",
2219 qeth_get_cardname(card
),
2220 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2221 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2222 (card
->info
.mcl_level
[0]) ? ")" : "",
2223 qeth_get_cardname_short(card
),
2228 static void qeth_print_status_no_portname(struct qeth_card
*card
)
2230 if (card
->info
.portname
[0])
2231 dev_info(&card
->gdev
->dev
, "Device is a%s "
2232 "card%s%s%s\nwith link type %s "
2233 "(no portname needed by interface).\n",
2234 qeth_get_cardname(card
),
2235 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2236 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2237 (card
->info
.mcl_level
[0]) ? ")" : "",
2238 qeth_get_cardname_short(card
));
2240 dev_info(&card
->gdev
->dev
, "Device is a%s "
2241 "card%s%s%s\nwith link type %s.\n",
2242 qeth_get_cardname(card
),
2243 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2244 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2245 (card
->info
.mcl_level
[0]) ? ")" : "",
2246 qeth_get_cardname_short(card
));
2249 void qeth_print_status_message(struct qeth_card
*card
)
2251 switch (card
->info
.type
) {
2252 case QETH_CARD_TYPE_OSAE
:
2253 /* VM will use a non-zero first character
2254 * to indicate a HiperSockets like reporting
2255 * of the level OSA sets the first character to zero
2257 if (!card
->info
.mcl_level
[0]) {
2258 sprintf(card
->info
.mcl_level
, "%02x%02x",
2259 card
->info
.mcl_level
[2],
2260 card
->info
.mcl_level
[3]);
2262 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2266 case QETH_CARD_TYPE_IQD
:
2267 if ((card
->info
.guestlan
) ||
2268 (card
->info
.mcl_level
[0] & 0x80)) {
2269 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2270 card
->info
.mcl_level
[0]];
2271 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2272 card
->info
.mcl_level
[1]];
2273 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2274 card
->info
.mcl_level
[2]];
2275 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2276 card
->info
.mcl_level
[3]];
2277 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2281 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2283 if (card
->info
.portname_required
)
2284 qeth_print_status_with_portname(card
);
2286 qeth_print_status_no_portname(card
);
2288 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2290 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2292 struct qeth_buffer_pool_entry
*entry
;
2294 QETH_DBF_TEXT(TRACE
, 5, "inwrklst");
2296 list_for_each_entry(entry
,
2297 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2298 qeth_put_buffer_pool_entry(card
, entry
);
2302 static inline struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2303 struct qeth_card
*card
)
2305 struct list_head
*plh
;
2306 struct qeth_buffer_pool_entry
*entry
;
2310 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2313 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2314 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2316 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2317 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2323 list_del_init(&entry
->list
);
2328 /* no free buffer in pool so take first one and swap pages */
2329 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2330 struct qeth_buffer_pool_entry
, list
);
2331 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2332 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2333 page
= alloc_page(GFP_ATOMIC
);
2337 free_page((unsigned long)entry
->elements
[i
]);
2338 entry
->elements
[i
] = page_address(page
);
2339 if (card
->options
.performance_stats
)
2340 card
->perf_stats
.sg_alloc_page_rx
++;
2344 list_del_init(&entry
->list
);
2348 static int qeth_init_input_buffer(struct qeth_card
*card
,
2349 struct qeth_qdio_buffer
*buf
)
2351 struct qeth_buffer_pool_entry
*pool_entry
;
2354 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2359 * since the buffer is accessed only from the input_tasklet
2360 * there shouldn't be a need to synchronize; also, since we use
2361 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2365 buf
->pool_entry
= pool_entry
;
2366 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2367 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2368 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2369 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2370 buf
->buffer
->element
[i
].flags
= SBAL_FLAGS_LAST_ENTRY
;
2372 buf
->buffer
->element
[i
].flags
= 0;
2377 int qeth_init_qdio_queues(struct qeth_card
*card
)
2382 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2385 memset(card
->qdio
.in_q
->qdio_bufs
, 0,
2386 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2387 qeth_initialize_working_pool_list(card
);
2388 /*give only as many buffers to hardware as we have buffer pool entries*/
2389 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2390 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2391 card
->qdio
.in_q
->next_buf_to_init
=
2392 card
->qdio
.in_buf_pool
.buf_count
- 1;
2393 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2394 card
->qdio
.in_buf_pool
.buf_count
- 1);
2396 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2399 /* outbound queue */
2400 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2401 memset(card
->qdio
.out_qs
[i
]->qdio_bufs
, 0,
2402 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2403 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2404 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2405 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
2407 card
->qdio
.out_qs
[i
]->card
= card
;
2408 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2409 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2410 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2411 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2412 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2413 QETH_OUT_Q_UNLOCKED
);
2417 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2419 static inline __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2421 switch (link_type
) {
2422 case QETH_LINK_TYPE_HSTR
:
2429 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2430 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2431 enum qeth_prot_versions prot
)
2433 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2434 cmd
->hdr
.command
= command
;
2435 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2436 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2437 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2438 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2439 if (card
->options
.layer2
)
2440 cmd
->hdr
.prim_version_no
= 2;
2442 cmd
->hdr
.prim_version_no
= 1;
2443 cmd
->hdr
.param_count
= 1;
2444 cmd
->hdr
.prot_version
= prot
;
2445 cmd
->hdr
.ipa_supported
= 0;
2446 cmd
->hdr
.ipa_enabled
= 0;
2449 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2450 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2452 struct qeth_cmd_buffer
*iob
;
2453 struct qeth_ipa_cmd
*cmd
;
2455 iob
= qeth_wait_for_buffer(&card
->write
);
2456 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2457 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2461 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2463 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2466 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2467 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2468 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2469 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2471 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2473 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2474 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2481 QETH_DBF_TEXT(TRACE
, 4, "sendipa");
2483 if (card
->options
.layer2
)
2484 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2485 prot_type
= QETH_PROT_OSN2
;
2487 prot_type
= QETH_PROT_LAYER2
;
2489 prot_type
= QETH_PROT_TCPIP
;
2490 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
2491 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
2492 iob
, reply_cb
, reply_param
);
2495 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
2497 static int qeth_send_startstoplan(struct qeth_card
*card
,
2498 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2501 struct qeth_cmd_buffer
*iob
;
2503 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, prot
);
2504 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
2509 int qeth_send_startlan(struct qeth_card
*card
)
2513 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
2515 rc
= qeth_send_startstoplan(card
, IPA_CMD_STARTLAN
, 0);
2518 EXPORT_SYMBOL_GPL(qeth_send_startlan
);
2520 int qeth_send_stoplan(struct qeth_card
*card
)
2525 * TODO: according to the IPA format document page 14,
2526 * TCP/IP (we!) never issue a STOPLAN
2529 QETH_DBF_TEXT(SETUP
, 2, "stoplan");
2531 rc
= qeth_send_startstoplan(card
, IPA_CMD_STOPLAN
, 0);
2534 EXPORT_SYMBOL_GPL(qeth_send_stoplan
);
2536 int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
2537 struct qeth_reply
*reply
, unsigned long data
)
2539 struct qeth_ipa_cmd
*cmd
;
2541 QETH_DBF_TEXT(TRACE
, 4, "defadpcb");
2543 cmd
= (struct qeth_ipa_cmd
*) data
;
2544 if (cmd
->hdr
.return_code
== 0)
2545 cmd
->hdr
.return_code
=
2546 cmd
->data
.setadapterparms
.hdr
.return_code
;
2549 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb
);
2551 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
2552 struct qeth_reply
*reply
, unsigned long data
)
2554 struct qeth_ipa_cmd
*cmd
;
2556 QETH_DBF_TEXT(TRACE
, 3, "quyadpcb");
2558 cmd
= (struct qeth_ipa_cmd
*) data
;
2559 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f)
2560 card
->info
.link_type
=
2561 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
2562 card
->options
.adp
.supported_funcs
=
2563 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
2564 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
2567 struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
2568 __u32 command
, __u32 cmdlen
)
2570 struct qeth_cmd_buffer
*iob
;
2571 struct qeth_ipa_cmd
*cmd
;
2573 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
2575 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2576 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
2577 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
2578 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
2579 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
2583 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd
);
2585 int qeth_query_setadapterparms(struct qeth_card
*card
)
2588 struct qeth_cmd_buffer
*iob
;
2590 QETH_DBF_TEXT(TRACE
, 3, "queryadp");
2591 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
2592 sizeof(struct qeth_ipacmd_setadpparms
));
2593 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
2596 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
2598 int qeth_check_qdio_errors(struct qdio_buffer
*buf
, unsigned int qdio_error
,
2599 const char *dbftext
)
2602 QETH_DBF_TEXT(TRACE
, 2, dbftext
);
2603 QETH_DBF_TEXT(QERR
, 2, dbftext
);
2604 QETH_DBF_TEXT_(QERR
, 2, " F15=%02X",
2605 buf
->element
[15].flags
& 0xff);
2606 QETH_DBF_TEXT_(QERR
, 2, " F14=%02X",
2607 buf
->element
[14].flags
& 0xff);
2608 QETH_DBF_TEXT_(QERR
, 2, " qerr=%X", qdio_error
);
2613 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors
);
2615 void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
2617 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
2623 count
= (index
< queue
->next_buf_to_init
)?
2624 card
->qdio
.in_buf_pool
.buf_count
-
2625 (queue
->next_buf_to_init
- index
) :
2626 card
->qdio
.in_buf_pool
.buf_count
-
2627 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
2628 /* only requeue at a certain threshold to avoid SIGAs */
2629 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
2630 for (i
= queue
->next_buf_to_init
;
2631 i
< queue
->next_buf_to_init
+ count
; ++i
) {
2632 if (qeth_init_input_buffer(card
,
2633 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
2640 if (newcount
< count
) {
2641 /* we are in memory shortage so we switch back to
2642 traditional skb allocation and drop packages */
2643 atomic_set(&card
->force_alloc_skb
, 3);
2646 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
2650 * according to old code it should be avoided to requeue all
2651 * 128 buffers in order to benefit from PCI avoidance.
2652 * this function keeps at least one buffer (the buffer at
2653 * 'index') un-requeued -> this buffer is the first buffer that
2654 * will be requeued the next time
2656 if (card
->options
.performance_stats
) {
2657 card
->perf_stats
.inbound_do_qdio_cnt
++;
2658 card
->perf_stats
.inbound_do_qdio_start_time
=
2661 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
2662 queue
->next_buf_to_init
, count
);
2663 if (card
->options
.performance_stats
)
2664 card
->perf_stats
.inbound_do_qdio_time
+=
2666 card
->perf_stats
.inbound_do_qdio_start_time
;
2668 dev_warn(&card
->gdev
->dev
,
2669 "QDIO reported an error, rc=%i\n", rc
);
2670 QETH_DBF_TEXT(TRACE
, 2, "qinberr");
2671 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
2673 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
2674 QDIO_MAX_BUFFERS_PER_Q
;
2677 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer
);
2679 static int qeth_handle_send_error(struct qeth_card
*card
,
2680 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
2682 int sbalf15
= buffer
->buffer
->element
[15].flags
& 0xff;
2684 QETH_DBF_TEXT(TRACE
, 6, "hdsnderr");
2685 qeth_check_qdio_errors(buffer
->buffer
, qdio_err
, "qouterr");
2688 return QETH_SEND_ERROR_NONE
;
2690 if ((sbalf15
>= 15) && (sbalf15
<= 31))
2691 return QETH_SEND_ERROR_RETRY
;
2693 QETH_DBF_TEXT(TRACE
, 1, "lnkfail");
2694 QETH_DBF_TEXT_(TRACE
, 1, "%s", CARD_BUS_ID(card
));
2695 QETH_DBF_TEXT_(TRACE
, 1, "%04x %02x",
2696 (u16
)qdio_err
, (u8
)sbalf15
);
2697 return QETH_SEND_ERROR_LINK_FAILURE
;
2701 * Switched to packing state if the number of used buffers on a queue
2702 * reaches a certain limit.
2704 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
2706 if (!queue
->do_pack
) {
2707 if (atomic_read(&queue
->used_buffers
)
2708 >= QETH_HIGH_WATERMARK_PACK
){
2709 /* switch non-PACKING -> PACKING */
2710 QETH_DBF_TEXT(TRACE
, 6, "np->pack");
2711 if (queue
->card
->options
.performance_stats
)
2712 queue
->card
->perf_stats
.sc_dp_p
++;
2719 * Switches from packing to non-packing mode. If there is a packing
2720 * buffer on the queue this buffer will be prepared to be flushed.
2721 * In that case 1 is returned to inform the caller. If no buffer
2722 * has to be flushed, zero is returned.
2724 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
2726 struct qeth_qdio_out_buffer
*buffer
;
2727 int flush_count
= 0;
2729 if (queue
->do_pack
) {
2730 if (atomic_read(&queue
->used_buffers
)
2731 <= QETH_LOW_WATERMARK_PACK
) {
2732 /* switch PACKING -> non-PACKING */
2733 QETH_DBF_TEXT(TRACE
, 6, "pack->np");
2734 if (queue
->card
->options
.performance_stats
)
2735 queue
->card
->perf_stats
.sc_p_dp
++;
2737 /* flush packing buffers */
2738 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
2739 if ((atomic_read(&buffer
->state
) ==
2740 QETH_QDIO_BUF_EMPTY
) &&
2741 (buffer
->next_element_to_fill
> 0)) {
2742 atomic_set(&buffer
->state
,
2743 QETH_QDIO_BUF_PRIMED
);
2745 queue
->next_buf_to_fill
=
2746 (queue
->next_buf_to_fill
+ 1) %
2747 QDIO_MAX_BUFFERS_PER_Q
;
2755 * Called to flush a packing buffer if no more pci flags are on the queue.
2756 * Checks if there is a packing buffer and prepares it to be flushed.
2757 * In that case returns 1, otherwise zero.
2759 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q
*queue
)
2761 struct qeth_qdio_out_buffer
*buffer
;
2763 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
2764 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
2765 (buffer
->next_element_to_fill
> 0)) {
2766 /* it's a packing buffer */
2767 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
2768 queue
->next_buf_to_fill
=
2769 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
2775 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
2778 struct qeth_qdio_out_buffer
*buf
;
2781 unsigned int qdio_flags
;
2783 for (i
= index
; i
< index
+ count
; ++i
) {
2784 buf
= &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
];
2785 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].flags
|=
2786 SBAL_FLAGS_LAST_ENTRY
;
2788 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
2791 if (!queue
->do_pack
) {
2792 if ((atomic_read(&queue
->used_buffers
) >=
2793 (QETH_HIGH_WATERMARK_PACK
-
2794 QETH_WATERMARK_PACK_FUZZ
)) &&
2795 !atomic_read(&queue
->set_pci_flags_count
)) {
2796 /* it's likely that we'll go to packing
2798 atomic_inc(&queue
->set_pci_flags_count
);
2799 buf
->buffer
->element
[0].flags
|= 0x40;
2802 if (!atomic_read(&queue
->set_pci_flags_count
)) {
2804 * there's no outstanding PCI any more, so we
2805 * have to request a PCI to be sure the the PCI
2806 * will wake at some time in the future then we
2807 * can flush packed buffers that might still be
2808 * hanging around, which can happen if no
2809 * further send was requested by the stack
2811 atomic_inc(&queue
->set_pci_flags_count
);
2812 buf
->buffer
->element
[0].flags
|= 0x40;
2817 queue
->card
->dev
->trans_start
= jiffies
;
2818 if (queue
->card
->options
.performance_stats
) {
2819 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
2820 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
2823 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
2824 if (atomic_read(&queue
->set_pci_flags_count
))
2825 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
2826 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
2827 queue
->queue_no
, index
, count
);
2828 if (queue
->card
->options
.performance_stats
)
2829 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
2831 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
2833 queue
->card
->stats
.tx_errors
+= count
;
2834 /* ignore temporary SIGA errors without busy condition */
2835 if (rc
== QDIO_ERROR_SIGA_TARGET
)
2837 QETH_DBF_TEXT(TRACE
, 2, "flushbuf");
2838 QETH_DBF_TEXT_(TRACE
, 2, " err%d", rc
);
2839 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_DDEV_ID(queue
->card
));
2841 /* this must not happen under normal circumstances. if it
2842 * happens something is really wrong -> recover */
2843 qeth_schedule_recovery(queue
->card
);
2846 atomic_add(count
, &queue
->used_buffers
);
2847 if (queue
->card
->options
.performance_stats
)
2848 queue
->card
->perf_stats
.bufs_sent
+= count
;
2851 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
2855 int q_was_packing
= 0;
2858 * check if weed have to switch to non-packing mode or if
2859 * we have to get a pci flag out on the queue
2861 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
2862 !atomic_read(&queue
->set_pci_flags_count
)) {
2863 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
2864 QETH_OUT_Q_UNLOCKED
) {
2866 * If we get in here, there was no action in
2867 * do_send_packet. So, we check if there is a
2868 * packing buffer to be flushed here.
2870 netif_stop_queue(queue
->card
->dev
);
2871 index
= queue
->next_buf_to_fill
;
2872 q_was_packing
= queue
->do_pack
;
2873 /* queue->do_pack may change */
2875 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
2877 !atomic_read(&queue
->set_pci_flags_count
))
2879 qeth_flush_buffers_on_no_pci(queue
);
2880 if (queue
->card
->options
.performance_stats
&&
2882 queue
->card
->perf_stats
.bufs_sent_pack
+=
2885 qeth_flush_buffers(queue
, index
, flush_cnt
);
2886 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
2891 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
2892 unsigned int qdio_error
, int __queue
, int first_element
,
2893 int count
, unsigned long card_ptr
)
2895 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
2896 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
2897 struct qeth_qdio_out_buffer
*buffer
;
2900 QETH_DBF_TEXT(TRACE
, 6, "qdouhdl");
2901 if (qdio_error
& QDIO_ERROR_ACTIVATE_CHECK_CONDITION
) {
2902 QETH_DBF_TEXT(TRACE
, 2, "achkcond");
2903 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
2904 netif_stop_queue(card
->dev
);
2905 qeth_schedule_recovery(card
);
2908 if (card
->options
.performance_stats
) {
2909 card
->perf_stats
.outbound_handler_cnt
++;
2910 card
->perf_stats
.outbound_handler_start_time
=
2913 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
2914 buffer
= &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
];
2915 qeth_handle_send_error(card
, buffer
, qdio_error
);
2916 qeth_clear_output_buffer(queue
, buffer
);
2918 atomic_sub(count
, &queue
->used_buffers
);
2919 /* check if we need to do something on this outbound queue */
2920 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
2921 qeth_check_outbound_queue(queue
);
2923 netif_wake_queue(queue
->card
->dev
);
2924 if (card
->options
.performance_stats
)
2925 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
2926 card
->perf_stats
.outbound_handler_start_time
;
2928 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
2930 int qeth_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
2932 int cast_type
= RTN_UNSPEC
;
2934 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2937 if (skb
->dst
&& skb
->dst
->neighbour
) {
2938 cast_type
= skb
->dst
->neighbour
->type
;
2939 if ((cast_type
== RTN_BROADCAST
) ||
2940 (cast_type
== RTN_MULTICAST
) ||
2941 (cast_type
== RTN_ANYCAST
))
2946 /* try something else */
2947 if (skb
->protocol
== ETH_P_IPV6
)
2948 return (skb_network_header(skb
)[24] == 0xff) ?
2950 else if (skb
->protocol
== ETH_P_IP
)
2951 return ((skb_network_header(skb
)[16] & 0xf0) == 0xe0) ?
2954 if (!memcmp(skb
->data
, skb
->dev
->broadcast
, 6))
2955 return RTN_BROADCAST
;
2959 hdr_mac
= *((u16
*)skb
->data
);
2961 switch (card
->info
.link_type
) {
2962 case QETH_LINK_TYPE_HSTR
:
2963 case QETH_LINK_TYPE_LANE_TR
:
2964 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
2965 (hdr_mac
== QETH_TR_MAC_C
))
2966 return RTN_MULTICAST
;
2968 /* eth or so multicast? */
2970 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
2971 (hdr_mac
== QETH_ETH_MAC_V6
))
2972 return RTN_MULTICAST
;
2977 EXPORT_SYMBOL_GPL(qeth_get_cast_type
);
2979 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
2980 int ipv
, int cast_type
)
2982 if (!ipv
&& (card
->info
.type
== QETH_CARD_TYPE_OSAE
))
2983 return card
->qdio
.default_out_queue
;
2984 switch (card
->qdio
.no_out_queues
) {
2986 if (cast_type
&& card
->info
.is_multicast_different
)
2987 return card
->info
.is_multicast_different
&
2988 (card
->qdio
.no_out_queues
- 1);
2989 if (card
->qdio
.do_prio_queueing
&& (ipv
== 4)) {
2990 const u8 tos
= ip_hdr(skb
)->tos
;
2992 if (card
->qdio
.do_prio_queueing
==
2993 QETH_PRIO_Q_ING_TOS
) {
2994 if (tos
& IP_TOS_NOTIMPORTANT
)
2996 if (tos
& IP_TOS_HIGHRELIABILITY
)
2998 if (tos
& IP_TOS_HIGHTHROUGHPUT
)
3000 if (tos
& IP_TOS_LOWDELAY
)
3003 if (card
->qdio
.do_prio_queueing
==
3004 QETH_PRIO_Q_ING_PREC
)
3005 return 3 - (tos
>> 6);
3006 } else if (card
->qdio
.do_prio_queueing
&& (ipv
== 6)) {
3009 return card
->qdio
.default_out_queue
;
3010 case 1: /* fallthrough for single-out-queue 1920-device */
3012 return card
->qdio
.default_out_queue
;
3015 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
3017 int qeth_get_elements_no(struct qeth_card
*card
, void *hdr
,
3018 struct sk_buff
*skb
, int elems
)
3020 int elements_needed
= 0;
3022 if (skb_shinfo(skb
)->nr_frags
> 0)
3023 elements_needed
= (skb_shinfo(skb
)->nr_frags
+ 1);
3024 if (elements_needed
== 0)
3025 elements_needed
= 1 + (((((unsigned long) skb
->data
) %
3026 PAGE_SIZE
) + skb
->len
) >> PAGE_SHIFT
);
3027 if ((elements_needed
+ elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3028 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3029 "(Number=%d / Length=%d). Discarded.\n",
3030 (elements_needed
+elems
), skb
->len
);
3033 return elements_needed
;
3035 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3037 static inline void __qeth_fill_buffer(struct sk_buff
*skb
,
3038 struct qdio_buffer
*buffer
, int is_tso
, int *next_element_to_fill
,
3041 int length
= skb
->len
;
3047 element
= *next_element_to_fill
;
3049 first_lap
= (is_tso
== 0 ? 1 : 0);
3052 data
= skb
->data
+ offset
;
3057 while (length
> 0) {
3058 /* length_here is the remaining amount of data in this page */
3059 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3060 if (length
< length_here
)
3061 length_here
= length
;
3063 buffer
->element
[element
].addr
= data
;
3064 buffer
->element
[element
].length
= length_here
;
3065 length
-= length_here
;
3068 buffer
->element
[element
].flags
= 0;
3070 buffer
->element
[element
].flags
=
3071 SBAL_FLAGS_LAST_FRAG
;
3074 buffer
->element
[element
].flags
=
3075 SBAL_FLAGS_FIRST_FRAG
;
3077 buffer
->element
[element
].flags
=
3078 SBAL_FLAGS_MIDDLE_FRAG
;
3080 data
+= length_here
;
3084 *next_element_to_fill
= element
;
3087 static inline int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
3088 struct qeth_qdio_out_buffer
*buf
, struct sk_buff
*skb
,
3089 struct qeth_hdr
*hdr
, int offset
, int hd_len
)
3091 struct qdio_buffer
*buffer
;
3092 int flush_cnt
= 0, hdr_len
, large_send
= 0;
3094 buffer
= buf
->buffer
;
3095 atomic_inc(&skb
->users
);
3096 skb_queue_tail(&buf
->skb_list
, skb
);
3098 /*check first on TSO ....*/
3099 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_TSO
) {
3100 int element
= buf
->next_element_to_fill
;
3102 hdr_len
= sizeof(struct qeth_hdr_tso
) +
3103 ((struct qeth_hdr_tso
*)hdr
)->ext
.dg_hdr_len
;
3104 /*fill first buffer entry only with header information */
3105 buffer
->element
[element
].addr
= skb
->data
;
3106 buffer
->element
[element
].length
= hdr_len
;
3107 buffer
->element
[element
].flags
= SBAL_FLAGS_FIRST_FRAG
;
3108 buf
->next_element_to_fill
++;
3109 skb
->data
+= hdr_len
;
3110 skb
->len
-= hdr_len
;
3115 int element
= buf
->next_element_to_fill
;
3116 buffer
->element
[element
].addr
= hdr
;
3117 buffer
->element
[element
].length
= sizeof(struct qeth_hdr
) +
3119 buffer
->element
[element
].flags
= SBAL_FLAGS_FIRST_FRAG
;
3120 buf
->is_header
[element
] = 1;
3121 buf
->next_element_to_fill
++;
3124 if (skb_shinfo(skb
)->nr_frags
== 0)
3125 __qeth_fill_buffer(skb
, buffer
, large_send
,
3126 (int *)&buf
->next_element_to_fill
, offset
);
3128 __qeth_fill_buffer_frag(skb
, buffer
, large_send
,
3129 (int *)&buf
->next_element_to_fill
);
3131 if (!queue
->do_pack
) {
3132 QETH_DBF_TEXT(TRACE
, 6, "fillbfnp");
3133 /* set state to PRIMED -> will be flushed */
3134 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3137 QETH_DBF_TEXT(TRACE
, 6, "fillbfpa");
3138 if (queue
->card
->options
.performance_stats
)
3139 queue
->card
->perf_stats
.skbs_sent_pack
++;
3140 if (buf
->next_element_to_fill
>=
3141 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
3143 * packed buffer if full -> set state PRIMED
3144 * -> will be flushed
3146 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3153 int qeth_do_send_packet_fast(struct qeth_card
*card
,
3154 struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
3155 struct qeth_hdr
*hdr
, int elements_needed
,
3156 int offset
, int hd_len
)
3158 struct qeth_qdio_out_buffer
*buffer
;
3161 /* spin until we get the queue ... */
3162 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3163 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3164 /* ... now we've got the queue */
3165 index
= queue
->next_buf_to_fill
;
3166 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3168 * check if buffer is empty to make sure that we do not 'overtake'
3169 * ourselves and try to fill a buffer that is already primed
3171 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
3173 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ 1) %
3174 QDIO_MAX_BUFFERS_PER_Q
;
3175 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3176 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
3177 qeth_flush_buffers(queue
, index
, 1);
3180 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3183 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
3185 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
3186 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
3187 int elements_needed
)
3189 struct qeth_qdio_out_buffer
*buffer
;
3191 int flush_count
= 0;
3196 /* spin until we get the queue ... */
3197 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3198 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3199 start_index
= queue
->next_buf_to_fill
;
3200 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3202 * check if buffer is empty to make sure that we do not 'overtake'
3203 * ourselves and try to fill a buffer that is already primed
3205 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
3206 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3209 /* check if we need to switch packing state of this queue */
3210 qeth_switch_to_packing_if_needed(queue
);
3211 if (queue
->do_pack
) {
3213 /* does packet fit in current buffer? */
3214 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
3215 buffer
->next_element_to_fill
) < elements_needed
) {
3216 /* ... no -> set state PRIMED */
3217 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3219 queue
->next_buf_to_fill
=
3220 (queue
->next_buf_to_fill
+ 1) %
3221 QDIO_MAX_BUFFERS_PER_Q
;
3222 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3223 /* we did a step forward, so check buffer state
3225 if (atomic_read(&buffer
->state
) !=
3226 QETH_QDIO_BUF_EMPTY
) {
3227 qeth_flush_buffers(queue
, start_index
,
3229 atomic_set(&queue
->state
,
3230 QETH_OUT_Q_UNLOCKED
);
3235 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, -1, 0);
3236 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
3237 QDIO_MAX_BUFFERS_PER_Q
;
3240 qeth_flush_buffers(queue
, start_index
, flush_count
);
3241 else if (!atomic_read(&queue
->set_pci_flags_count
))
3242 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
3244 * queue->state will go from LOCKED -> UNLOCKED or from
3245 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3246 * (switch packing state or flush buffer to get another pci flag out).
3247 * In that case we will enter this loop
3249 while (atomic_dec_return(&queue
->state
)) {
3251 start_index
= queue
->next_buf_to_fill
;
3252 /* check if we can go back to non-packing state */
3253 flush_count
+= qeth_switch_to_nonpacking_if_needed(queue
);
3255 * check if we need to flush a packing buffer to get a pci
3256 * flag out on the queue
3258 if (!flush_count
&& !atomic_read(&queue
->set_pci_flags_count
))
3259 flush_count
+= qeth_flush_buffers_on_no_pci(queue
);
3261 qeth_flush_buffers(queue
, start_index
, flush_count
);
3263 /* at this point the queue is UNLOCKED again */
3264 if (queue
->card
->options
.performance_stats
&& do_pack
)
3265 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
3269 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
3271 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
3272 struct qeth_reply
*reply
, unsigned long data
)
3274 struct qeth_ipa_cmd
*cmd
;
3275 struct qeth_ipacmd_setadpparms
*setparms
;
3277 QETH_DBF_TEXT(TRACE
, 4, "prmadpcb");
3279 cmd
= (struct qeth_ipa_cmd
*) data
;
3280 setparms
= &(cmd
->data
.setadapterparms
);
3282 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
3283 if (cmd
->hdr
.return_code
) {
3284 QETH_DBF_TEXT_(TRACE
, 4, "prmrc%2.2x", cmd
->hdr
.return_code
);
3285 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
3287 card
->info
.promisc_mode
= setparms
->data
.mode
;
3291 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
3293 enum qeth_ipa_promisc_modes mode
;
3294 struct net_device
*dev
= card
->dev
;
3295 struct qeth_cmd_buffer
*iob
;
3296 struct qeth_ipa_cmd
*cmd
;
3298 QETH_DBF_TEXT(TRACE
, 4, "setprom");
3300 if (((dev
->flags
& IFF_PROMISC
) &&
3301 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
3302 (!(dev
->flags
& IFF_PROMISC
) &&
3303 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
3305 mode
= SET_PROMISC_MODE_OFF
;
3306 if (dev
->flags
& IFF_PROMISC
)
3307 mode
= SET_PROMISC_MODE_ON
;
3308 QETH_DBF_TEXT_(TRACE
, 4, "mode:%x", mode
);
3310 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
3311 sizeof(struct qeth_ipacmd_setadpparms
));
3312 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
3313 cmd
->data
.setadapterparms
.data
.mode
= mode
;
3314 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
3316 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
3318 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
3320 struct qeth_card
*card
;
3323 card
= dev
->ml_priv
;
3325 QETH_DBF_TEXT(TRACE
, 4, "chgmtu");
3326 sprintf(dbf_text
, "%8x", new_mtu
);
3327 QETH_DBF_TEXT(TRACE
, 4, dbf_text
);
3331 if (new_mtu
> 65535)
3333 if ((!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) &&
3334 (!qeth_mtu_is_valid(card
, new_mtu
)))
3339 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
3341 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
3343 struct qeth_card
*card
;
3345 card
= dev
->ml_priv
;
3347 QETH_DBF_TEXT(TRACE
, 5, "getstat");
3349 return &card
->stats
;
3351 EXPORT_SYMBOL_GPL(qeth_get_stats
);
3353 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
3354 struct qeth_reply
*reply
, unsigned long data
)
3356 struct qeth_ipa_cmd
*cmd
;
3358 QETH_DBF_TEXT(TRACE
, 4, "chgmaccb");
3360 cmd
= (struct qeth_ipa_cmd
*) data
;
3361 if (!card
->options
.layer2
||
3362 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
3363 memcpy(card
->dev
->dev_addr
,
3364 &cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
3366 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
3368 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3372 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
3375 struct qeth_cmd_buffer
*iob
;
3376 struct qeth_ipa_cmd
*cmd
;
3378 QETH_DBF_TEXT(TRACE
, 4, "chgmac");
3380 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
3381 sizeof(struct qeth_ipacmd_setadpparms
));
3382 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3383 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
3384 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= OSA_ADDR_LEN
;
3385 memcpy(&cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
3386 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
3387 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
3391 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
3393 void qeth_tx_timeout(struct net_device
*dev
)
3395 struct qeth_card
*card
;
3397 card
= dev
->ml_priv
;
3398 card
->stats
.tx_errors
++;
3399 qeth_schedule_recovery(card
);
3401 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
3403 int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
3405 struct qeth_card
*card
= dev
->ml_priv
;
3409 case MII_BMCR
: /* Basic mode control register */
3411 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
3412 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
3413 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
3414 rc
|= BMCR_SPEED100
;
3416 case MII_BMSR
: /* Basic mode status register */
3417 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
3418 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
3421 case MII_PHYSID1
: /* PHYS ID 1 */
3422 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
3424 rc
= (rc
>> 5) & 0xFFFF;
3426 case MII_PHYSID2
: /* PHYS ID 2 */
3427 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
3429 case MII_ADVERTISE
: /* Advertisement control reg */
3432 case MII_LPA
: /* Link partner ability reg */
3433 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
3434 LPA_100BASE4
| LPA_LPACK
;
3436 case MII_EXPANSION
: /* Expansion register */
3438 case MII_DCOUNTER
: /* disconnect counter */
3440 case MII_FCSCOUNTER
: /* false carrier counter */
3442 case MII_NWAYTEST
: /* N-way auto-neg test register */
3444 case MII_RERRCOUNTER
: /* rx error counter */
3445 rc
= card
->stats
.rx_errors
;
3447 case MII_SREVISION
: /* silicon revision */
3449 case MII_RESV1
: /* reserved 1 */
3451 case MII_LBRERROR
: /* loopback, rx, bypass error */
3453 case MII_PHYADDR
: /* physical address */
3455 case MII_RESV2
: /* reserved 2 */
3457 case MII_TPISTATUS
: /* TPI status for 10mbps */
3459 case MII_NCONFIG
: /* network interface config */
3466 EXPORT_SYMBOL_GPL(qeth_mdio_read
);
3468 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
3469 struct qeth_cmd_buffer
*iob
, int len
,
3470 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
3476 QETH_DBF_TEXT(TRACE
, 4, "sendsnmp");
3478 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
3479 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
3480 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
3481 /* adjust PDU length fields in IPA_PDU_HEADER */
3482 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
3484 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
3485 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
3486 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
3487 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
3488 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
3489 reply_cb
, reply_param
);
3492 static int qeth_snmp_command_cb(struct qeth_card
*card
,
3493 struct qeth_reply
*reply
, unsigned long sdata
)
3495 struct qeth_ipa_cmd
*cmd
;
3496 struct qeth_arp_query_info
*qinfo
;
3497 struct qeth_snmp_cmd
*snmp
;
3498 unsigned char *data
;
3501 QETH_DBF_TEXT(TRACE
, 3, "snpcmdcb");
3503 cmd
= (struct qeth_ipa_cmd
*) sdata
;
3504 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
3505 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
3506 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
3508 if (cmd
->hdr
.return_code
) {
3509 QETH_DBF_TEXT_(TRACE
, 4, "scer1%i", cmd
->hdr
.return_code
);
3512 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
3513 cmd
->hdr
.return_code
=
3514 cmd
->data
.setadapterparms
.hdr
.return_code
;
3515 QETH_DBF_TEXT_(TRACE
, 4, "scer2%i", cmd
->hdr
.return_code
);
3518 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
3519 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
3520 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
3522 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
3524 /* check if there is enough room in userspace */
3525 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
3526 QETH_DBF_TEXT_(TRACE
, 4, "scer3%i", -ENOMEM
);
3527 cmd
->hdr
.return_code
= -ENOMEM
;
3530 QETH_DBF_TEXT_(TRACE
, 4, "snore%i",
3531 cmd
->data
.setadapterparms
.hdr
.used_total
);
3532 QETH_DBF_TEXT_(TRACE
, 4, "sseqn%i",
3533 cmd
->data
.setadapterparms
.hdr
.seq_no
);
3534 /*copy entries to user buffer*/
3535 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
3536 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
3538 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
3539 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
3541 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
3542 (char *)&snmp
->request
, data_len
);
3544 qinfo
->udata_offset
+= data_len
;
3545 /* check if all replies received ... */
3546 QETH_DBF_TEXT_(TRACE
, 4, "srtot%i",
3547 cmd
->data
.setadapterparms
.hdr
.used_total
);
3548 QETH_DBF_TEXT_(TRACE
, 4, "srseq%i",
3549 cmd
->data
.setadapterparms
.hdr
.seq_no
);
3550 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
3551 cmd
->data
.setadapterparms
.hdr
.used_total
)
3556 int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
3558 struct qeth_cmd_buffer
*iob
;
3559 struct qeth_ipa_cmd
*cmd
;
3560 struct qeth_snmp_ureq
*ureq
;
3562 struct qeth_arp_query_info qinfo
= {0, };
3565 QETH_DBF_TEXT(TRACE
, 3, "snmpcmd");
3567 if (card
->info
.guestlan
)
3570 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
3571 (!card
->options
.layer2
)) {
3574 /* skip 4 bytes (data_len struct member) to get req_len */
3575 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
3577 ureq
= kmalloc(req_len
+sizeof(struct qeth_snmp_ureq_hdr
), GFP_KERNEL
);
3579 QETH_DBF_TEXT(TRACE
, 2, "snmpnome");
3582 if (copy_from_user(ureq
, udata
,
3583 req_len
+ sizeof(struct qeth_snmp_ureq_hdr
))) {
3587 qinfo
.udata_len
= ureq
->hdr
.data_len
;
3588 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
3593 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
3595 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
3596 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
3597 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3598 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
3599 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
3600 qeth_snmp_command_cb
, (void *)&qinfo
);
3602 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
3603 QETH_CARD_IFNAME(card
), rc
);
3605 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
3613 EXPORT_SYMBOL_GPL(qeth_snmp_command
);
3615 static inline int qeth_get_qdio_q_format(struct qeth_card
*card
)
3617 switch (card
->info
.type
) {
3618 case QETH_CARD_TYPE_IQD
:
3625 static int qeth_qdio_establish(struct qeth_card
*card
)
3627 struct qdio_initialize init_data
;
3628 char *qib_param_field
;
3629 struct qdio_buffer
**in_sbal_ptrs
;
3630 struct qdio_buffer
**out_sbal_ptrs
;
3634 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
3636 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
3638 if (!qib_param_field
)
3641 qeth_create_qib_param_field(card
, qib_param_field
);
3642 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
3644 in_sbal_ptrs
= kmalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
3646 if (!in_sbal_ptrs
) {
3647 kfree(qib_param_field
);
3650 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
3651 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
3652 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
3655 kmalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
3656 sizeof(void *), GFP_KERNEL
);
3657 if (!out_sbal_ptrs
) {
3658 kfree(in_sbal_ptrs
);
3659 kfree(qib_param_field
);
3662 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
3663 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
3664 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
3665 card
->qdio
.out_qs
[i
]->bufs
[j
].buffer
);
3668 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
3669 init_data
.cdev
= CARD_DDEV(card
);
3670 init_data
.q_format
= qeth_get_qdio_q_format(card
);
3671 init_data
.qib_param_field_format
= 0;
3672 init_data
.qib_param_field
= qib_param_field
;
3673 init_data
.no_input_qs
= 1;
3674 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
3675 init_data
.input_handler
= card
->discipline
.input_handler
;
3676 init_data
.output_handler
= card
->discipline
.output_handler
;
3677 init_data
.int_parm
= (unsigned long) card
;
3678 init_data
.flags
= QDIO_INBOUND_0COPY_SBALS
|
3679 QDIO_OUTBOUND_0COPY_SBALS
|
3680 QDIO_USE_OUTBOUND_PCIS
;
3681 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
3682 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
3684 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
3685 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
3686 rc
= qdio_initialize(&init_data
);
3688 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
3690 kfree(out_sbal_ptrs
);
3691 kfree(in_sbal_ptrs
);
3692 kfree(qib_param_field
);
3696 static void qeth_core_free_card(struct qeth_card
*card
)
3699 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
3700 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3701 qeth_clean_channel(&card
->read
);
3702 qeth_clean_channel(&card
->write
);
3704 free_netdev(card
->dev
);
3705 kfree(card
->ip_tbd_list
);
3706 qeth_free_qdio_buffers(card
);
3707 unregister_service_level(&card
->qeth_service_level
);
3711 static struct ccw_device_id qeth_ids
[] = {
3712 {CCW_DEVICE(0x1731, 0x01), .driver_info
= QETH_CARD_TYPE_OSAE
},
3713 {CCW_DEVICE(0x1731, 0x05), .driver_info
= QETH_CARD_TYPE_IQD
},
3714 {CCW_DEVICE(0x1731, 0x06), .driver_info
= QETH_CARD_TYPE_OSN
},
3717 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
3719 static struct ccw_driver qeth_ccw_driver
= {
3722 .probe
= ccwgroup_probe_ccwdev
,
3723 .remove
= ccwgroup_remove_ccwdev
,
3726 static int qeth_core_driver_group(const char *buf
, struct device
*root_dev
,
3727 unsigned long driver_id
)
3729 return ccwgroup_create_from_string(root_dev
, driver_id
,
3730 &qeth_ccw_driver
, 3, buf
);
3733 int qeth_core_hardsetup_card(struct qeth_card
*card
)
3735 struct qdio_ssqd_desc
*ssqd
;
3740 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
3741 atomic_set(&card
->force_alloc_skb
, 0);
3744 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
3745 dev_name(&card
->gdev
->dev
));
3746 ccw_device_set_offline(CARD_DDEV(card
));
3747 ccw_device_set_offline(CARD_WDEV(card
));
3748 ccw_device_set_offline(CARD_RDEV(card
));
3749 ccw_device_set_online(CARD_RDEV(card
));
3750 ccw_device_set_online(CARD_WDEV(card
));
3751 ccw_device_set_online(CARD_DDEV(card
));
3753 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
3754 if (rc
== -ERESTARTSYS
) {
3755 QETH_DBF_TEXT(SETUP
, 2, "break1");
3758 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3765 rc
= qeth_get_unitaddr(card
);
3767 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
3771 ssqd
= kmalloc(sizeof(struct qdio_ssqd_desc
), GFP_KERNEL
);
3776 rc
= qdio_get_ssqd_desc(CARD_DDEV(card
), ssqd
);
3782 mpno
= min(mpno
- 1, QETH_MAX_PORTNO
);
3783 if (card
->info
.portno
> mpno
) {
3784 QETH_DBF_MESSAGE(2, "Device %s does not offer port number %d"
3785 "\n.", CARD_BUS_ID(card
), card
->info
.portno
);
3789 qeth_init_tokens(card
);
3790 qeth_init_func_level(card
);
3791 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
3792 if (rc
== -ERESTARTSYS
) {
3793 QETH_DBF_TEXT(SETUP
, 2, "break2");
3796 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3802 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
3803 if (rc
== -ERESTARTSYS
) {
3804 QETH_DBF_TEXT(SETUP
, 2, "break3");
3807 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3813 rc
= qeth_mpc_initialize(card
);
3815 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3820 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
3821 "an error on the device\n");
3822 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
3823 dev_name(&card
->gdev
->dev
), rc
);
3826 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
3828 static inline int qeth_create_skb_frag(struct qdio_buffer_element
*element
,
3829 struct sk_buff
**pskb
, int offset
, int *pfrag
, int data_len
)
3831 struct page
*page
= virt_to_page(element
->addr
);
3832 if (*pskb
== NULL
) {
3833 /* the upper protocol layers assume that there is data in the
3834 * skb itself. Copy a small amount (64 bytes) to make them
3836 *pskb
= dev_alloc_skb(64 + ETH_HLEN
);
3839 skb_reserve(*pskb
, ETH_HLEN
);
3840 if (data_len
<= 64) {
3841 memcpy(skb_put(*pskb
, data_len
), element
->addr
+ offset
,
3845 memcpy(skb_put(*pskb
, 64), element
->addr
+ offset
, 64);
3846 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
+ 64,
3848 (*pskb
)->data_len
+= data_len
- 64;
3849 (*pskb
)->len
+= data_len
- 64;
3850 (*pskb
)->truesize
+= data_len
- 64;
3855 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
, data_len
);
3856 (*pskb
)->data_len
+= data_len
;
3857 (*pskb
)->len
+= data_len
;
3858 (*pskb
)->truesize
+= data_len
;
3864 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
3865 struct qdio_buffer
*buffer
,
3866 struct qdio_buffer_element
**__element
, int *__offset
,
3867 struct qeth_hdr
**hdr
)
3869 struct qdio_buffer_element
*element
= *__element
;
3870 int offset
= *__offset
;
3871 struct sk_buff
*skb
= NULL
;
3879 /* qeth_hdr must not cross element boundaries */
3880 if (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
3881 if (qeth_is_last_sbale(element
))
3885 if (element
->length
< sizeof(struct qeth_hdr
))
3888 *hdr
= element
->addr
+ offset
;
3890 offset
+= sizeof(struct qeth_hdr
);
3891 if (card
->options
.layer2
) {
3892 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
3893 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
3894 headroom
= sizeof(struct qeth_hdr
);
3896 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
3899 skb_len
= (*hdr
)->hdr
.l3
.length
;
3900 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
3901 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
))
3904 headroom
= ETH_HLEN
;
3910 if ((skb_len
>= card
->options
.rx_sg_cb
) &&
3911 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
3912 (!atomic_read(&card
->force_alloc_skb
))) {
3915 skb
= dev_alloc_skb(skb_len
+ headroom
);
3919 skb_reserve(skb
, headroom
);
3922 data_ptr
= element
->addr
+ offset
;
3924 data_len
= min(skb_len
, (int)(element
->length
- offset
));
3927 if (qeth_create_skb_frag(element
, &skb
, offset
,
3931 memcpy(skb_put(skb
, data_len
), data_ptr
,
3935 skb_len
-= data_len
;
3937 if (qeth_is_last_sbale(element
)) {
3938 QETH_DBF_TEXT(TRACE
, 4, "unexeob");
3939 QETH_DBF_TEXT_(TRACE
, 4, "%s",
3941 QETH_DBF_TEXT(QERR
, 2, "unexeob");
3942 QETH_DBF_TEXT_(QERR
, 2, "%s",
3944 QETH_DBF_HEX(MISC
, 4, buffer
, sizeof(*buffer
));
3945 dev_kfree_skb_any(skb
);
3946 card
->stats
.rx_errors
++;
3951 data_ptr
= element
->addr
;
3956 *__element
= element
;
3958 if (use_rx_sg
&& card
->options
.performance_stats
) {
3959 card
->perf_stats
.sg_skbs_rx
++;
3960 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
3964 if (net_ratelimit()) {
3965 QETH_DBF_TEXT(TRACE
, 2, "noskbmem");
3966 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
3968 card
->stats
.rx_dropped
++;
3971 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
3973 static void qeth_unregister_dbf_views(void)
3976 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
3977 debug_unregister(qeth_dbf
[x
].id
);
3978 qeth_dbf
[x
].id
= NULL
;
3982 void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix
, int level
, char *fmt
, ...)
3984 char dbf_txt_buf
[32];
3987 if (level
> (qeth_dbf
[dbf_nix
].id
)->level
)
3989 va_start(args
, fmt
);
3990 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
3992 debug_text_event(qeth_dbf
[dbf_nix
].id
, level
, dbf_txt_buf
);
3994 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
3996 static int qeth_register_dbf_views(void)
4001 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
4002 /* register the areas */
4003 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
4007 if (qeth_dbf
[x
].id
== NULL
) {
4008 qeth_unregister_dbf_views();
4012 /* register a view */
4013 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
4015 qeth_unregister_dbf_views();
4019 /* set a passing level */
4020 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
4026 int qeth_core_load_discipline(struct qeth_card
*card
,
4027 enum qeth_discipline_id discipline
)
4030 switch (discipline
) {
4031 case QETH_DISCIPLINE_LAYER3
:
4032 card
->discipline
.ccwgdriver
= try_then_request_module(
4033 symbol_get(qeth_l3_ccwgroup_driver
),
4036 case QETH_DISCIPLINE_LAYER2
:
4037 card
->discipline
.ccwgdriver
= try_then_request_module(
4038 symbol_get(qeth_l2_ccwgroup_driver
),
4042 if (!card
->discipline
.ccwgdriver
) {
4043 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
4044 "support discipline %d\n", discipline
);
4050 void qeth_core_free_discipline(struct qeth_card
*card
)
4052 if (card
->options
.layer2
)
4053 symbol_put(qeth_l2_ccwgroup_driver
);
4055 symbol_put(qeth_l3_ccwgroup_driver
);
4056 card
->discipline
.ccwgdriver
= NULL
;
4059 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
4061 struct qeth_card
*card
;
4064 unsigned long flags
;
4066 QETH_DBF_TEXT(SETUP
, 2, "probedev");
4069 if (!get_device(dev
))
4072 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
4074 card
= qeth_alloc_card();
4076 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
4080 card
->read
.ccwdev
= gdev
->cdev
[0];
4081 card
->write
.ccwdev
= gdev
->cdev
[1];
4082 card
->data
.ccwdev
= gdev
->cdev
[2];
4083 dev_set_drvdata(&gdev
->dev
, card
);
4085 gdev
->cdev
[0]->handler
= qeth_irq
;
4086 gdev
->cdev
[1]->handler
= qeth_irq
;
4087 gdev
->cdev
[2]->handler
= qeth_irq
;
4089 rc
= qeth_determine_card_type(card
);
4091 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4094 rc
= qeth_setup_card(card
);
4096 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
4100 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
4101 rc
= qeth_core_create_osn_attributes(dev
);
4104 rc
= qeth_core_load_discipline(card
, QETH_DISCIPLINE_LAYER2
);
4106 qeth_core_remove_osn_attributes(dev
);
4109 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
4111 qeth_core_free_discipline(card
);
4112 qeth_core_remove_osn_attributes(dev
);
4116 rc
= qeth_core_create_device_attributes(dev
);
4121 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
4122 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
4123 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
4127 qeth_core_free_card(card
);
4133 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
4135 unsigned long flags
;
4136 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4138 QETH_DBF_TEXT(SETUP
, 2, "removedv");
4139 if (card
->discipline
.ccwgdriver
) {
4140 card
->discipline
.ccwgdriver
->remove(gdev
);
4141 qeth_core_free_discipline(card
);
4144 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
4145 qeth_core_remove_osn_attributes(&gdev
->dev
);
4147 qeth_core_remove_device_attributes(&gdev
->dev
);
4149 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
4150 list_del(&card
->list
);
4151 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
4152 qeth_core_free_card(card
);
4153 dev_set_drvdata(&gdev
->dev
, NULL
);
4154 put_device(&gdev
->dev
);
4158 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
4160 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4164 if (!card
->discipline
.ccwgdriver
) {
4165 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
4166 def_discipline
= QETH_DISCIPLINE_LAYER3
;
4168 def_discipline
= QETH_DISCIPLINE_LAYER2
;
4169 rc
= qeth_core_load_discipline(card
, def_discipline
);
4172 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
4176 rc
= card
->discipline
.ccwgdriver
->set_online(gdev
);
4181 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
4183 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4184 return card
->discipline
.ccwgdriver
->set_offline(gdev
);
4187 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
4189 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4190 if (card
->discipline
.ccwgdriver
&&
4191 card
->discipline
.ccwgdriver
->shutdown
)
4192 card
->discipline
.ccwgdriver
->shutdown(gdev
);
4195 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
4196 .owner
= THIS_MODULE
,
4198 .driver_id
= 0xD8C5E3C8,
4199 .probe
= qeth_core_probe_device
,
4200 .remove
= qeth_core_remove_device
,
4201 .set_online
= qeth_core_set_online
,
4202 .set_offline
= qeth_core_set_offline
,
4203 .shutdown
= qeth_core_shutdown
,
4207 qeth_core_driver_group_store(struct device_driver
*ddrv
, const char *buf
,
4211 err
= qeth_core_driver_group(buf
, qeth_core_root_dev
,
4212 qeth_core_ccwgroup_driver
.driver_id
);
4219 static DRIVER_ATTR(group
, 0200, NULL
, qeth_core_driver_group_store
);
4222 const char str
[ETH_GSTRING_LEN
];
4223 } qeth_ethtool_stats_keys
[] = {
4228 {"tx skbs no packing"},
4229 {"tx buffers no packing"},
4230 {"tx skbs packing"},
4231 {"tx buffers packing"},
4234 /* 10 */{"rx sg skbs"},
4236 {"rx sg page allocs"},
4237 {"tx large kbytes"},
4239 {"tx pk state ch n->p"},
4240 {"tx pk state ch p->n"},
4241 {"tx pk watermark low"},
4242 {"tx pk watermark high"},
4243 {"queue 0 buffer usage"},
4244 /* 20 */{"queue 1 buffer usage"},
4245 {"queue 2 buffer usage"},
4246 {"queue 3 buffer usage"},
4247 {"rx handler time"},
4248 {"rx handler count"},
4249 {"rx do_QDIO time"},
4250 {"rx do_QDIO count"},
4251 {"tx handler time"},
4252 {"tx handler count"},
4254 /* 30 */{"tx count"},
4255 {"tx do_QDIO time"},
4256 {"tx do_QDIO count"},
4260 int qeth_core_get_stats_count(struct net_device
*dev
)
4262 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
4264 EXPORT_SYMBOL_GPL(qeth_core_get_stats_count
);
4266 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
4267 struct ethtool_stats
*stats
, u64
*data
)
4269 struct qeth_card
*card
= dev
->ml_priv
;
4270 data
[0] = card
->stats
.rx_packets
-
4271 card
->perf_stats
.initial_rx_packets
;
4272 data
[1] = card
->perf_stats
.bufs_rec
;
4273 data
[2] = card
->stats
.tx_packets
-
4274 card
->perf_stats
.initial_tx_packets
;
4275 data
[3] = card
->perf_stats
.bufs_sent
;
4276 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
4277 - card
->perf_stats
.skbs_sent_pack
;
4278 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
4279 data
[6] = card
->perf_stats
.skbs_sent_pack
;
4280 data
[7] = card
->perf_stats
.bufs_sent_pack
;
4281 data
[8] = card
->perf_stats
.sg_skbs_sent
;
4282 data
[9] = card
->perf_stats
.sg_frags_sent
;
4283 data
[10] = card
->perf_stats
.sg_skbs_rx
;
4284 data
[11] = card
->perf_stats
.sg_frags_rx
;
4285 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
4286 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
4287 data
[14] = card
->perf_stats
.large_send_cnt
;
4288 data
[15] = card
->perf_stats
.sc_dp_p
;
4289 data
[16] = card
->perf_stats
.sc_p_dp
;
4290 data
[17] = QETH_LOW_WATERMARK_PACK
;
4291 data
[18] = QETH_HIGH_WATERMARK_PACK
;
4292 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
4293 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
4294 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
4295 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
4296 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
4297 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
4298 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
4299 data
[23] = card
->perf_stats
.inbound_time
;
4300 data
[24] = card
->perf_stats
.inbound_cnt
;
4301 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
4302 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
4303 data
[27] = card
->perf_stats
.outbound_handler_time
;
4304 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
4305 data
[29] = card
->perf_stats
.outbound_time
;
4306 data
[30] = card
->perf_stats
.outbound_cnt
;
4307 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
4308 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
4309 data
[33] = card
->perf_stats
.tx_csum
;
4311 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
4313 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
4315 switch (stringset
) {
4317 memcpy(data
, &qeth_ethtool_stats_keys
,
4318 sizeof(qeth_ethtool_stats_keys
));
4325 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
4327 void qeth_core_get_drvinfo(struct net_device
*dev
,
4328 struct ethtool_drvinfo
*info
)
4330 struct qeth_card
*card
= dev
->ml_priv
;
4331 if (card
->options
.layer2
)
4332 strcpy(info
->driver
, "qeth_l2");
4334 strcpy(info
->driver
, "qeth_l3");
4336 strcpy(info
->version
, "1.0");
4337 strcpy(info
->fw_version
, card
->info
.mcl_level
);
4338 sprintf(info
->bus_info
, "%s/%s/%s",
4341 CARD_DDEV_ID(card
));
4343 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
4345 int qeth_core_ethtool_get_settings(struct net_device
*netdev
,
4346 struct ethtool_cmd
*ecmd
)
4348 struct qeth_card
*card
= netdev
->ml_priv
;
4349 enum qeth_link_types link_type
;
4351 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
4352 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
4354 link_type
= card
->info
.link_type
;
4356 ecmd
->transceiver
= XCVR_INTERNAL
;
4357 ecmd
->supported
= SUPPORTED_Autoneg
;
4358 ecmd
->advertising
= ADVERTISED_Autoneg
;
4359 ecmd
->duplex
= DUPLEX_FULL
;
4360 ecmd
->autoneg
= AUTONEG_ENABLE
;
4362 switch (link_type
) {
4363 case QETH_LINK_TYPE_FAST_ETH
:
4364 case QETH_LINK_TYPE_LANE_ETH100
:
4365 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4366 SUPPORTED_10baseT_Full
|
4367 SUPPORTED_100baseT_Half
|
4368 SUPPORTED_100baseT_Full
|
4370 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4371 ADVERTISED_10baseT_Full
|
4372 ADVERTISED_100baseT_Half
|
4373 ADVERTISED_100baseT_Full
|
4375 ecmd
->speed
= SPEED_100
;
4376 ecmd
->port
= PORT_TP
;
4379 case QETH_LINK_TYPE_GBIT_ETH
:
4380 case QETH_LINK_TYPE_LANE_ETH1000
:
4381 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4382 SUPPORTED_10baseT_Full
|
4383 SUPPORTED_100baseT_Half
|
4384 SUPPORTED_100baseT_Full
|
4385 SUPPORTED_1000baseT_Half
|
4386 SUPPORTED_1000baseT_Full
|
4388 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4389 ADVERTISED_10baseT_Full
|
4390 ADVERTISED_100baseT_Half
|
4391 ADVERTISED_100baseT_Full
|
4392 ADVERTISED_1000baseT_Half
|
4393 ADVERTISED_1000baseT_Full
|
4395 ecmd
->speed
= SPEED_1000
;
4396 ecmd
->port
= PORT_FIBRE
;
4399 case QETH_LINK_TYPE_10GBIT_ETH
:
4400 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4401 SUPPORTED_10baseT_Full
|
4402 SUPPORTED_100baseT_Half
|
4403 SUPPORTED_100baseT_Full
|
4404 SUPPORTED_1000baseT_Half
|
4405 SUPPORTED_1000baseT_Full
|
4406 SUPPORTED_10000baseT_Full
|
4408 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4409 ADVERTISED_10baseT_Full
|
4410 ADVERTISED_100baseT_Half
|
4411 ADVERTISED_100baseT_Full
|
4412 ADVERTISED_1000baseT_Half
|
4413 ADVERTISED_1000baseT_Full
|
4414 ADVERTISED_10000baseT_Full
|
4416 ecmd
->speed
= SPEED_10000
;
4417 ecmd
->port
= PORT_FIBRE
;
4421 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4422 SUPPORTED_10baseT_Full
|
4424 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4425 ADVERTISED_10baseT_Full
|
4427 ecmd
->speed
= SPEED_10
;
4428 ecmd
->port
= PORT_TP
;
4433 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings
);
4435 static int __init
qeth_core_init(void)
4439 pr_info("loading core functions\n");
4440 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
4441 rwlock_init(&qeth_core_card_list
.rwlock
);
4443 rc
= qeth_register_dbf_views();
4446 rc
= ccw_driver_register(&qeth_ccw_driver
);
4449 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
4452 rc
= driver_create_file(&qeth_core_ccwgroup_driver
.driver
,
4453 &driver_attr_group
);
4456 qeth_core_root_dev
= root_device_register("qeth");
4457 rc
= IS_ERR(qeth_core_root_dev
) ? PTR_ERR(qeth_core_root_dev
) : 0;
4461 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
4462 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
4463 if (!qeth_core_header_cache
) {
4470 root_device_unregister(qeth_core_root_dev
);
4472 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
4473 &driver_attr_group
);
4475 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
4477 ccw_driver_unregister(&qeth_ccw_driver
);
4479 QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc
);
4480 qeth_unregister_dbf_views();
4482 pr_err("Initializing the qeth device driver failed\n");
4486 static void __exit
qeth_core_exit(void)
4488 root_device_unregister(qeth_core_root_dev
);
4489 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
4490 &driver_attr_group
);
4491 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
4492 ccw_driver_unregister(&qeth_ccw_driver
);
4493 kmem_cache_destroy(qeth_core_header_cache
);
4494 qeth_unregister_dbf_views();
4495 pr_info("core functions removed\n");
4498 module_init(qeth_core_init
);
4499 module_exit(qeth_core_exit
);
4500 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
4501 MODULE_DESCRIPTION("qeth core functions");
4502 MODULE_LICENSE("GPL");