2 * drivers/s390/net/qeth_l2_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 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/string.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/etherdevice.h>
17 #include <linux/mii.h>
20 #include <asm/s390_rdev.h>
22 #include "qeth_core.h"
23 #include "qeth_core_offl.h"
25 #define QETH_DBF_TEXT_(name, level, text...) \
27 if (qeth_dbf_passes(qeth_dbf_##name, level)) { \
28 char *dbf_txt_buf = get_cpu_var(qeth_l2_dbf_txt_buf); \
29 sprintf(dbf_txt_buf, text); \
30 debug_text_event(qeth_dbf_##name, level, dbf_txt_buf); \
31 put_cpu_var(qeth_l2_dbf_txt_buf); \
35 static DEFINE_PER_CPU(char[256], qeth_l2_dbf_txt_buf
);
37 static int qeth_l2_set_offline(struct ccwgroup_device
*);
38 static int qeth_l2_stop(struct net_device
*);
39 static int qeth_l2_send_delmac(struct qeth_card
*, __u8
*);
40 static int qeth_l2_send_setdelmac(struct qeth_card
*, __u8
*,
42 int (*reply_cb
) (struct qeth_card
*,
45 static void qeth_l2_set_multicast_list(struct net_device
*);
46 static int qeth_l2_recover(void *);
48 static int qeth_l2_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
50 struct qeth_card
*card
= netdev_priv(dev
);
51 struct mii_ioctl_data
*mii_data
;
57 if ((card
->state
!= CARD_STATE_UP
) &&
58 (card
->state
!= CARD_STATE_SOFTSETUP
))
61 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
65 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
66 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
68 case SIOC_QETH_GET_CARD_TYPE
:
69 if ((card
->info
.type
== QETH_CARD_TYPE_OSAE
) &&
75 mii_data
= if_mii(rq
);
79 mii_data
= if_mii(rq
);
80 if (mii_data
->phy_id
!= 0)
83 mii_data
->val_out
= qeth_mdio_read(dev
,
84 mii_data
->phy_id
, mii_data
->reg_num
);
90 QETH_DBF_TEXT_(trace
, 2, "ioce%d", rc
);
94 static int qeth_l2_verify_dev(struct net_device
*dev
)
96 struct qeth_card
*card
;
100 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
101 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
102 if (card
->dev
== dev
) {
107 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
112 static struct net_device
*qeth_l2_netdev_by_devno(unsigned char *read_dev_no
)
114 struct qeth_card
*card
;
115 struct net_device
*ndev
;
116 unsigned char *readno
;
117 __u16 temp_dev_no
, card_dev_no
;
122 memcpy(&temp_dev_no
, read_dev_no
, 2);
123 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
124 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
125 readno
= CARD_RDEV_ID(card
);
126 readno
+= (strlen(readno
) - 4);
127 card_dev_no
= simple_strtoul(readno
, &endp
, 16);
128 if (card_dev_no
== temp_dev_no
) {
133 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
137 static int qeth_l2_send_setgroupmac_cb(struct qeth_card
*card
,
138 struct qeth_reply
*reply
,
141 struct qeth_ipa_cmd
*cmd
;
144 QETH_DBF_TEXT(trace
, 2, "L2Sgmacb");
145 cmd
= (struct qeth_ipa_cmd
*) data
;
146 mac
= &cmd
->data
.setdelmac
.mac
[0];
147 /* MAC already registered, needed in couple/uncouple case */
148 if (cmd
->hdr
.return_code
== 0x2005) {
149 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
150 "already existing on %s \n",
151 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5],
152 QETH_CARD_IFNAME(card
));
153 cmd
->hdr
.return_code
= 0;
155 if (cmd
->hdr
.return_code
)
156 PRINT_ERR("Could not set group MAC " \
157 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
158 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5],
159 QETH_CARD_IFNAME(card
), cmd
->hdr
.return_code
);
163 static int qeth_l2_send_setgroupmac(struct qeth_card
*card
, __u8
*mac
)
165 QETH_DBF_TEXT(trace
, 2, "L2Sgmac");
166 return qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_SETGMAC
,
167 qeth_l2_send_setgroupmac_cb
);
170 static int qeth_l2_send_delgroupmac_cb(struct qeth_card
*card
,
171 struct qeth_reply
*reply
,
174 struct qeth_ipa_cmd
*cmd
;
177 QETH_DBF_TEXT(trace
, 2, "L2Dgmacb");
178 cmd
= (struct qeth_ipa_cmd
*) data
;
179 mac
= &cmd
->data
.setdelmac
.mac
[0];
180 if (cmd
->hdr
.return_code
)
181 PRINT_ERR("Could not delete group MAC " \
182 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
183 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5],
184 QETH_CARD_IFNAME(card
), cmd
->hdr
.return_code
);
188 static int qeth_l2_send_delgroupmac(struct qeth_card
*card
, __u8
*mac
)
190 QETH_DBF_TEXT(trace
, 2, "L2Dgmac");
191 return qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_DELGMAC
,
192 qeth_l2_send_delgroupmac_cb
);
195 static void qeth_l2_add_mc(struct qeth_card
*card
, __u8
*mac
)
197 struct qeth_mc_mac
*mc
;
199 mc
= kmalloc(sizeof(struct qeth_mc_mac
), GFP_ATOMIC
);
202 PRINT_ERR("no mem vor mc mac address\n");
206 memcpy(mc
->mc_addr
, mac
, OSA_ADDR_LEN
);
207 mc
->mc_addrlen
= OSA_ADDR_LEN
;
209 if (!qeth_l2_send_setgroupmac(card
, mac
))
210 list_add_tail(&mc
->list
, &card
->mc_list
);
215 static void qeth_l2_del_all_mc(struct qeth_card
*card
)
217 struct qeth_mc_mac
*mc
, *tmp
;
219 spin_lock_bh(&card
->mclock
);
220 list_for_each_entry_safe(mc
, tmp
, &card
->mc_list
, list
) {
221 qeth_l2_send_delgroupmac(card
, mc
->mc_addr
);
225 spin_unlock_bh(&card
->mclock
);
228 static void qeth_l2_get_packet_type(struct qeth_card
*card
,
229 struct qeth_hdr
*hdr
, struct sk_buff
*skb
)
233 if (!memcmp(skb
->data
+ QETH_HEADER_SIZE
,
234 skb
->dev
->broadcast
, 6)) {
236 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_BROADCAST
;
239 hdr_mac
= *((__u16
*)skb
->data
);
241 switch (card
->info
.link_type
) {
242 case QETH_LINK_TYPE_HSTR
:
243 case QETH_LINK_TYPE_LANE_TR
:
244 if ((hdr_mac
== QETH_TR_MAC_NC
) ||
245 (hdr_mac
== QETH_TR_MAC_C
))
246 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
248 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_UNICAST
;
250 /* eth or so multicast? */
252 if ((hdr_mac
== QETH_ETH_MAC_V4
) ||
253 (hdr_mac
== QETH_ETH_MAC_V6
))
254 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
256 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_UNICAST
;
260 static void qeth_l2_fill_header(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
261 struct sk_buff
*skb
, int ipv
, int cast_type
)
263 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)((skb
->data
) +
266 memset(hdr
, 0, sizeof(struct qeth_hdr
));
267 hdr
->hdr
.l2
.id
= QETH_HEADER_TYPE_LAYER2
;
269 /* set byte byte 3 to casting flags */
270 if (cast_type
== RTN_MULTICAST
)
271 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
272 else if (cast_type
== RTN_BROADCAST
)
273 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_BROADCAST
;
275 qeth_l2_get_packet_type(card
, hdr
, skb
);
277 hdr
->hdr
.l2
.pkt_length
= skb
->len
-QETH_HEADER_SIZE
;
278 /* VSWITCH relies on the VLAN
279 * information to be present in
281 if (veth
->h_vlan_proto
== __constant_htons(ETH_P_8021Q
)) {
282 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_VLAN
;
283 hdr
->hdr
.l2
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
287 static int qeth_l2_send_setdelvlan_cb(struct qeth_card
*card
,
288 struct qeth_reply
*reply
, unsigned long data
)
290 struct qeth_ipa_cmd
*cmd
;
292 QETH_DBF_TEXT(trace
, 2, "L2sdvcb");
293 cmd
= (struct qeth_ipa_cmd
*) data
;
294 if (cmd
->hdr
.return_code
) {
295 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
296 "Continuing\n", cmd
->data
.setdelvlan
.vlan_id
,
297 QETH_CARD_IFNAME(card
), cmd
->hdr
.return_code
);
298 QETH_DBF_TEXT_(trace
, 2, "L2VL%4x", cmd
->hdr
.command
);
299 QETH_DBF_TEXT_(trace
, 2, "L2%s", CARD_BUS_ID(card
));
300 QETH_DBF_TEXT_(trace
, 2, "err%d", cmd
->hdr
.return_code
);
305 static int qeth_l2_send_setdelvlan(struct qeth_card
*card
, __u16 i
,
306 enum qeth_ipa_cmds ipacmd
)
308 struct qeth_ipa_cmd
*cmd
;
309 struct qeth_cmd_buffer
*iob
;
311 QETH_DBF_TEXT_(trace
, 4, "L2sdv%x", ipacmd
);
312 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
313 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
314 cmd
->data
.setdelvlan
.vlan_id
= i
;
315 return qeth_send_ipa_cmd(card
, iob
,
316 qeth_l2_send_setdelvlan_cb
, NULL
);
319 static void qeth_l2_process_vlans(struct qeth_card
*card
, int clear
)
321 struct qeth_vlan_vid
*id
;
322 QETH_DBF_TEXT(trace
, 3, "L2prcvln");
323 spin_lock_bh(&card
->vlanlock
);
324 list_for_each_entry(id
, &card
->vid_list
, list
) {
326 qeth_l2_send_setdelvlan(card
, id
->vid
,
329 qeth_l2_send_setdelvlan(card
, id
->vid
,
332 spin_unlock_bh(&card
->vlanlock
);
335 static void qeth_l2_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
337 struct qeth_card
*card
= netdev_priv(dev
);
338 struct qeth_vlan_vid
*id
;
340 QETH_DBF_TEXT_(trace
, 4, "aid:%d", vid
);
341 id
= kmalloc(sizeof(struct qeth_vlan_vid
), GFP_ATOMIC
);
344 qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_SETVLAN
);
345 spin_lock_bh(&card
->vlanlock
);
346 list_add_tail(&id
->list
, &card
->vid_list
);
347 spin_unlock_bh(&card
->vlanlock
);
349 PRINT_ERR("no memory for vid\n");
353 static void qeth_l2_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
355 struct qeth_vlan_vid
*id
, *tmpid
= NULL
;
356 struct qeth_card
*card
= netdev_priv(dev
);
358 QETH_DBF_TEXT_(trace
, 4, "kid:%d", vid
);
359 spin_lock_bh(&card
->vlanlock
);
360 list_for_each_entry(id
, &card
->vid_list
, list
) {
361 if (id
->vid
== vid
) {
367 spin_unlock_bh(&card
->vlanlock
);
369 qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_DELVLAN
);
372 qeth_l2_set_multicast_list(card
->dev
);
375 static int qeth_l2_stop_card(struct qeth_card
*card
, int recovery_mode
)
379 QETH_DBF_TEXT(setup
, 2, "stopcard");
380 QETH_DBF_HEX(setup
, 2, &card
, sizeof(void *));
382 qeth_set_allowed_threads(card
, 0, 1);
383 if (qeth_wait_for_threads(card
, ~QETH_RECOVER_THREAD
))
385 if (card
->read
.state
== CH_STATE_UP
&&
386 card
->write
.state
== CH_STATE_UP
&&
387 (card
->state
== CARD_STATE_UP
)) {
389 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
390 qeth_l2_stop(card
->dev
);
393 dev_close(card
->dev
);
396 if (!card
->use_hard_stop
) {
397 __u8
*mac
= &card
->dev
->dev_addr
[0];
398 rc
= qeth_l2_send_delmac(card
, mac
);
399 QETH_DBF_TEXT_(setup
, 2, "Lerr%d", rc
);
401 card
->state
= CARD_STATE_SOFTSETUP
;
403 if (card
->state
== CARD_STATE_SOFTSETUP
) {
404 qeth_l2_process_vlans(card
, 1);
405 qeth_l2_del_all_mc(card
);
406 qeth_clear_ipacmd_list(card
);
407 card
->state
= CARD_STATE_HARDSETUP
;
409 if (card
->state
== CARD_STATE_HARDSETUP
) {
410 qeth_qdio_clear_card(card
, 0);
411 qeth_clear_qdio_buffers(card
);
412 qeth_clear_working_pool_list(card
);
413 card
->state
= CARD_STATE_DOWN
;
415 if (card
->state
== CARD_STATE_DOWN
) {
416 qeth_clear_cmd_buffers(&card
->read
);
417 qeth_clear_cmd_buffers(&card
->write
);
419 card
->use_hard_stop
= 0;
423 static void qeth_l2_process_inbound_buffer(struct qeth_card
*card
,
424 struct qeth_qdio_buffer
*buf
, int index
)
426 struct qdio_buffer_element
*element
;
428 struct qeth_hdr
*hdr
;
432 /* get first element of current buffer */
433 element
= (struct qdio_buffer_element
*)&buf
->buffer
->element
[0];
435 if (card
->options
.performance_stats
)
436 card
->perf_stats
.bufs_rec
++;
437 while ((skb
= qeth_core_get_next_skb(card
, buf
->buffer
, &element
,
439 skb
->dev
= card
->dev
;
441 if (!(card
->dev
->flags
& IFF_UP
)) {
442 dev_kfree_skb_any(skb
);
446 switch (hdr
->hdr
.l2
.id
) {
447 case QETH_HEADER_TYPE_LAYER2
:
448 skb
->pkt_type
= PACKET_HOST
;
449 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
450 if (card
->options
.checksum_type
== NO_CHECKSUMMING
)
451 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
453 skb
->ip_summed
= CHECKSUM_NONE
;
454 *((__u32
*)skb
->cb
) = ++card
->seqno
.pkt_seqno
;
458 case QETH_HEADER_TYPE_OSN
:
459 skb_push(skb
, sizeof(struct qeth_hdr
));
460 skb_copy_to_linear_data(skb
, hdr
,
461 sizeof(struct qeth_hdr
));
463 card
->osn_info
.data_cb(skb
);
466 dev_kfree_skb_any(skb
);
467 QETH_DBF_TEXT(trace
, 3, "inbunkno");
468 QETH_DBF_HEX(control
, 3, hdr
, QETH_DBF_CONTROL_LEN
);
471 card
->dev
->last_rx
= jiffies
;
472 card
->stats
.rx_packets
++;
473 card
->stats
.rx_bytes
+= len
;
477 static int qeth_l2_send_setdelmac(struct qeth_card
*card
, __u8
*mac
,
478 enum qeth_ipa_cmds ipacmd
,
479 int (*reply_cb
) (struct qeth_card
*,
483 struct qeth_ipa_cmd
*cmd
;
484 struct qeth_cmd_buffer
*iob
;
486 QETH_DBF_TEXT(trace
, 2, "L2sdmac");
487 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
488 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
489 cmd
->data
.setdelmac
.mac_length
= OSA_ADDR_LEN
;
490 memcpy(&cmd
->data
.setdelmac
.mac
, mac
, OSA_ADDR_LEN
);
491 return qeth_send_ipa_cmd(card
, iob
, reply_cb
, NULL
);
494 static int qeth_l2_send_setmac_cb(struct qeth_card
*card
,
495 struct qeth_reply
*reply
,
498 struct qeth_ipa_cmd
*cmd
;
500 QETH_DBF_TEXT(trace
, 2, "L2Smaccb");
501 cmd
= (struct qeth_ipa_cmd
*) data
;
502 if (cmd
->hdr
.return_code
) {
503 QETH_DBF_TEXT_(trace
, 2, "L2er%x", cmd
->hdr
.return_code
);
504 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
505 cmd
->hdr
.return_code
= -EIO
;
507 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
508 memcpy(card
->dev
->dev_addr
, cmd
->data
.setdelmac
.mac
,
510 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
511 "successfully registered on device %s\n",
512 card
->dev
->dev_addr
[0], card
->dev
->dev_addr
[1],
513 card
->dev
->dev_addr
[2], card
->dev
->dev_addr
[3],
514 card
->dev
->dev_addr
[4], card
->dev
->dev_addr
[5],
520 static int qeth_l2_send_setmac(struct qeth_card
*card
, __u8
*mac
)
522 QETH_DBF_TEXT(trace
, 2, "L2Setmac");
523 return qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_SETVMAC
,
524 qeth_l2_send_setmac_cb
);
527 static int qeth_l2_send_delmac_cb(struct qeth_card
*card
,
528 struct qeth_reply
*reply
,
531 struct qeth_ipa_cmd
*cmd
;
533 QETH_DBF_TEXT(trace
, 2, "L2Dmaccb");
534 cmd
= (struct qeth_ipa_cmd
*) data
;
535 if (cmd
->hdr
.return_code
) {
536 QETH_DBF_TEXT_(trace
, 2, "err%d", cmd
->hdr
.return_code
);
537 cmd
->hdr
.return_code
= -EIO
;
540 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
545 static int qeth_l2_send_delmac(struct qeth_card
*card
, __u8
*mac
)
547 QETH_DBF_TEXT(trace
, 2, "L2Delmac");
548 if (!(card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))
550 return qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_DELVMAC
,
551 qeth_l2_send_delmac_cb
);
554 static int qeth_l2_request_initial_mac(struct qeth_card
*card
)
557 char vendor_pre
[] = {0x02, 0x00, 0x00};
559 QETH_DBF_TEXT(setup
, 2, "doL2init");
560 QETH_DBF_TEXT_(setup
, 2, "doL2%s", CARD_BUS_ID(card
));
562 rc
= qeth_query_setadapterparms(card
);
564 PRINT_WARN("could not query adapter parameters on device %s: "
565 "x%x\n", CARD_BUS_ID(card
), rc
);
568 if (card
->info
.guestlan
) {
569 rc
= qeth_setadpparms_change_macaddr(card
);
571 PRINT_WARN("couldn't get MAC address on "
573 CARD_BUS_ID(card
), rc
);
574 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
577 QETH_DBF_HEX(setup
, 2, card
->dev
->dev_addr
, OSA_ADDR_LEN
);
579 random_ether_addr(card
->dev
->dev_addr
);
580 memcpy(card
->dev
->dev_addr
, vendor_pre
, 3);
585 static int qeth_l2_set_mac_address(struct net_device
*dev
, void *p
)
587 struct sockaddr
*addr
= p
;
588 struct qeth_card
*card
= netdev_priv(dev
);
591 QETH_DBF_TEXT(trace
, 3, "setmac");
593 if (qeth_l2_verify_dev(dev
) != QETH_REAL_CARD
) {
594 QETH_DBF_TEXT(trace
, 3, "setmcINV");
598 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
599 PRINT_WARN("Setting MAC address on %s is not supported.\n",
601 QETH_DBF_TEXT(trace
, 3, "setmcOSN");
604 QETH_DBF_TEXT_(trace
, 3, "%s", CARD_BUS_ID(card
));
605 QETH_DBF_HEX(trace
, 3, addr
->sa_data
, OSA_ADDR_LEN
);
606 rc
= qeth_l2_send_delmac(card
, &card
->dev
->dev_addr
[0]);
608 rc
= qeth_l2_send_setmac(card
, addr
->sa_data
);
612 static void qeth_l2_set_multicast_list(struct net_device
*dev
)
614 struct qeth_card
*card
= netdev_priv(dev
);
615 struct dev_mc_list
*dm
;
617 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
620 QETH_DBF_TEXT(trace
, 3, "setmulti");
621 qeth_l2_del_all_mc(card
);
622 spin_lock_bh(&card
->mclock
);
623 for (dm
= dev
->mc_list
; dm
; dm
= dm
->next
)
624 qeth_l2_add_mc(card
, dm
->dmi_addr
);
625 spin_unlock_bh(&card
->mclock
);
626 if (!qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
628 qeth_setadp_promisc_mode(card
);
631 static int qeth_l2_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
634 struct qeth_hdr
*hdr
= NULL
;
636 struct qeth_card
*card
= netdev_priv(dev
);
637 struct sk_buff
*new_skb
= skb
;
638 int ipv
= qeth_get_ip_version(skb
);
639 int cast_type
= qeth_get_cast_type(card
, skb
);
640 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
641 [qeth_get_priority_queue(card
, skb
, ipv
, cast_type
)];
642 int tx_bytes
= skb
->len
;
643 enum qeth_large_send_types large_send
= QETH_LARGE_SEND_NO
;
644 struct qeth_eddp_context
*ctx
= NULL
;
646 QETH_DBF_TEXT(trace
, 6, "l2xmit");
648 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
649 card
->stats
.tx_carrier_errors
++;
653 if ((card
->info
.type
== QETH_CARD_TYPE_OSN
) &&
654 (skb
->protocol
== htons(ETH_P_IPV6
)))
657 if (card
->options
.performance_stats
) {
658 card
->perf_stats
.outbound_cnt
++;
659 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
661 netif_stop_queue(dev
);
664 large_send
= QETH_LARGE_SEND_EDDP
;
666 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
667 hdr
= (struct qeth_hdr
*)skb
->data
;
669 new_skb
= qeth_prepare_skb(card
, skb
, &hdr
);
672 qeth_l2_fill_header(card
, hdr
, new_skb
, ipv
, cast_type
);
675 if (large_send
== QETH_LARGE_SEND_EDDP
) {
676 ctx
= qeth_eddp_create_context(card
, new_skb
, hdr
,
677 skb
->sk
->sk_protocol
);
679 PRINT_WARN("could not create eddp context\n");
683 elements
= qeth_get_elements_no(card
, (void *)hdr
, new_skb
, 0);
688 if ((large_send
== QETH_LARGE_SEND_NO
) &&
689 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
690 qeth_tx_csum(new_skb
);
692 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
693 rc
= qeth_do_send_packet(card
, queue
, new_skb
, hdr
,
696 rc
= qeth_do_send_packet_fast(card
, queue
, new_skb
, hdr
,
699 card
->stats
.tx_packets
++;
700 card
->stats
.tx_bytes
+= tx_bytes
;
702 dev_kfree_skb_any(skb
);
703 if (card
->options
.performance_stats
) {
704 if (large_send
!= QETH_LARGE_SEND_NO
) {
705 card
->perf_stats
.large_send_bytes
+= tx_bytes
;
706 card
->perf_stats
.large_send_cnt
++;
708 if (skb_shinfo(new_skb
)->nr_frags
> 0) {
709 card
->perf_stats
.sg_skbs_sent
++;
710 /* nr_frags + skb->data */
711 card
->perf_stats
.sg_frags_sent
+=
712 skb_shinfo(new_skb
)->nr_frags
+ 1;
717 qeth_eddp_put_context(ctx
);
718 dev_kfree_skb_any(new_skb
);
722 qeth_eddp_put_context(ctx
);
726 dev_kfree_skb_any(new_skb
);
727 return NETDEV_TX_BUSY
;
732 netif_wake_queue(dev
);
733 if (card
->options
.performance_stats
)
734 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
735 card
->perf_stats
.outbound_start_time
;
739 card
->stats
.tx_dropped
++;
740 card
->stats
.tx_errors
++;
741 if ((new_skb
!= skb
) && new_skb
)
742 dev_kfree_skb_any(new_skb
);
743 dev_kfree_skb_any(skb
);
747 static void qeth_l2_qdio_input_handler(struct ccw_device
*ccwdev
,
748 unsigned int status
, unsigned int qdio_err
,
749 unsigned int siga_err
, unsigned int queue
,
750 int first_element
, int count
, unsigned long card_ptr
)
752 struct net_device
*net_dev
;
753 struct qeth_card
*card
;
754 struct qeth_qdio_buffer
*buffer
;
758 QETH_DBF_TEXT(trace
, 6, "qdinput");
759 card
= (struct qeth_card
*) card_ptr
;
761 if (card
->options
.performance_stats
) {
762 card
->perf_stats
.inbound_cnt
++;
763 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
765 if (status
& QDIO_STATUS_LOOK_FOR_ERROR
) {
766 if (status
& QDIO_STATUS_ACTIVATE_CHECK_CONDITION
) {
767 QETH_DBF_TEXT(trace
, 1, "qdinchk");
768 QETH_DBF_TEXT_(trace
, 1, "%s", CARD_BUS_ID(card
));
769 QETH_DBF_TEXT_(trace
, 1, "%04X%04X", first_element
,
771 QETH_DBF_TEXT_(trace
, 1, "%04X%04X", queue
, status
);
772 qeth_schedule_recovery(card
);
776 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
777 index
= i
% QDIO_MAX_BUFFERS_PER_Q
;
778 buffer
= &card
->qdio
.in_q
->bufs
[index
];
779 if (!((status
& QDIO_STATUS_LOOK_FOR_ERROR
) &&
780 qeth_check_qdio_errors(buffer
->buffer
,
781 qdio_err
, siga_err
, "qinerr")))
782 qeth_l2_process_inbound_buffer(card
, buffer
, index
);
783 /* clear buffer and give back to hardware */
784 qeth_put_buffer_pool_entry(card
, buffer
->pool_entry
);
785 qeth_queue_input_buffer(card
, index
);
787 if (card
->options
.performance_stats
)
788 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
789 card
->perf_stats
.inbound_start_time
;
792 static int qeth_l2_open(struct net_device
*dev
)
794 struct qeth_card
*card
= netdev_priv(dev
);
796 QETH_DBF_TEXT(trace
, 4, "qethopen");
797 if (card
->state
!= CARD_STATE_SOFTSETUP
)
800 if ((card
->info
.type
!= QETH_CARD_TYPE_OSN
) &&
801 (!(card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))) {
802 QETH_DBF_TEXT(trace
, 4, "nomacadr");
805 card
->data
.state
= CH_STATE_UP
;
806 card
->state
= CARD_STATE_UP
;
807 card
->dev
->flags
|= IFF_UP
;
808 netif_start_queue(dev
);
810 if (!card
->lan_online
&& netif_carrier_ok(dev
))
811 netif_carrier_off(dev
);
816 static int qeth_l2_stop(struct net_device
*dev
)
818 struct qeth_card
*card
= netdev_priv(dev
);
820 QETH_DBF_TEXT(trace
, 4, "qethstop");
821 netif_tx_disable(dev
);
822 card
->dev
->flags
&= ~IFF_UP
;
823 if (card
->state
== CARD_STATE_UP
)
824 card
->state
= CARD_STATE_SOFTSETUP
;
828 static int qeth_l2_probe_device(struct ccwgroup_device
*gdev
)
830 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
832 INIT_LIST_HEAD(&card
->vid_list
);
833 INIT_LIST_HEAD(&card
->mc_list
);
834 card
->options
.layer2
= 1;
835 card
->discipline
.input_handler
= (qdio_handler_t
*)
836 qeth_l2_qdio_input_handler
;
837 card
->discipline
.output_handler
= (qdio_handler_t
*)
838 qeth_qdio_output_handler
;
839 card
->discipline
.recover
= qeth_l2_recover
;
843 static void qeth_l2_remove_device(struct ccwgroup_device
*cgdev
)
845 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
847 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
849 if (cgdev
->state
== CCWGROUP_ONLINE
) {
850 card
->use_hard_stop
= 1;
851 qeth_l2_set_offline(cgdev
);
855 unregister_netdev(card
->dev
);
859 qeth_l2_del_all_mc(card
);
863 static struct ethtool_ops qeth_l2_ethtool_ops
= {
864 .get_link
= ethtool_op_get_link
,
865 .get_tx_csum
= ethtool_op_get_tx_csum
,
866 .set_tx_csum
= ethtool_op_set_tx_hw_csum
,
867 .get_sg
= ethtool_op_get_sg
,
868 .set_sg
= ethtool_op_set_sg
,
869 .get_tso
= ethtool_op_get_tso
,
870 .set_tso
= ethtool_op_set_tso
,
871 .get_strings
= qeth_core_get_strings
,
872 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
873 .get_stats_count
= qeth_core_get_stats_count
,
874 .get_drvinfo
= qeth_core_get_drvinfo
,
877 static struct ethtool_ops qeth_l2_osn_ops
= {
878 .get_strings
= qeth_core_get_strings
,
879 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
880 .get_stats_count
= qeth_core_get_stats_count
,
881 .get_drvinfo
= qeth_core_get_drvinfo
,
884 static int qeth_l2_setup_netdev(struct qeth_card
*card
)
886 switch (card
->info
.type
) {
887 case QETH_CARD_TYPE_OSAE
:
888 card
->dev
= alloc_etherdev(0);
890 case QETH_CARD_TYPE_IQD
:
891 card
->dev
= alloc_netdev(0, "hsi%d", ether_setup
);
893 case QETH_CARD_TYPE_OSN
:
894 card
->dev
= alloc_netdev(0, "osn%d", ether_setup
);
895 card
->dev
->flags
|= IFF_NOARP
;
898 card
->dev
= alloc_etherdev(0);
904 card
->dev
->priv
= card
;
905 card
->dev
->tx_timeout
= &qeth_tx_timeout
;
906 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
907 card
->dev
->open
= qeth_l2_open
;
908 card
->dev
->stop
= qeth_l2_stop
;
909 card
->dev
->hard_start_xmit
= qeth_l2_hard_start_xmit
;
910 card
->dev
->do_ioctl
= qeth_l2_do_ioctl
;
911 card
->dev
->get_stats
= qeth_get_stats
;
912 card
->dev
->change_mtu
= qeth_change_mtu
;
913 card
->dev
->set_multicast_list
= qeth_l2_set_multicast_list
;
914 card
->dev
->vlan_rx_kill_vid
= qeth_l2_vlan_rx_kill_vid
;
915 card
->dev
->vlan_rx_add_vid
= qeth_l2_vlan_rx_add_vid
;
916 card
->dev
->set_mac_address
= qeth_l2_set_mac_address
;
917 card
->dev
->mtu
= card
->info
.initial_mtu
;
918 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
919 SET_ETHTOOL_OPS(card
->dev
, &qeth_l2_ethtool_ops
);
921 SET_ETHTOOL_OPS(card
->dev
, &qeth_l2_osn_ops
);
922 card
->dev
->features
|= NETIF_F_HW_VLAN_FILTER
;
923 card
->info
.broadcast_capable
= 1;
924 qeth_l2_request_initial_mac(card
);
925 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
926 return register_netdev(card
->dev
);
929 static int __qeth_l2_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
931 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
933 enum qeth_card_states recover_flag
;
936 QETH_DBF_TEXT(setup
, 2, "setonlin");
937 QETH_DBF_HEX(setup
, 2, &card
, sizeof(void *));
939 qeth_set_allowed_threads(card
, QETH_RECOVER_THREAD
, 1);
940 if (qeth_wait_for_threads(card
, ~QETH_RECOVER_THREAD
)) {
941 PRINT_WARN("set_online of card %s interrupted by user!\n",
946 recover_flag
= card
->state
;
947 rc
= ccw_device_set_online(CARD_RDEV(card
));
949 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
952 rc
= ccw_device_set_online(CARD_WDEV(card
));
954 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
957 rc
= ccw_device_set_online(CARD_DDEV(card
));
959 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
963 rc
= qeth_core_hardsetup_card(card
);
965 QETH_DBF_TEXT_(setup
, 2, "2err%d", rc
);
969 if (!card
->dev
&& qeth_l2_setup_netdev(card
))
972 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
973 qeth_l2_send_setmac(card
, &card
->dev
->dev_addr
[0]);
975 card
->state
= CARD_STATE_HARDSETUP
;
976 qeth_print_status_message(card
);
979 QETH_DBF_TEXT(setup
, 2, "softsetp");
981 rc
= qeth_send_startlan(card
);
983 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
985 PRINT_WARN("LAN on card %s if offline! "
986 "Waiting for STARTLAN from card.\n",
988 card
->lan_online
= 0;
992 card
->lan_online
= 1;
994 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
995 qeth_set_large_send(card
, card
->options
.large_send
);
996 qeth_l2_process_vlans(card
, 0);
999 netif_tx_disable(card
->dev
);
1001 rc
= qeth_init_qdio_queues(card
);
1003 QETH_DBF_TEXT_(setup
, 2, "6err%d", rc
);
1006 card
->state
= CARD_STATE_SOFTSETUP
;
1007 netif_carrier_on(card
->dev
);
1009 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1010 if (recover_flag
== CARD_STATE_RECOVER
) {
1011 if (recovery_mode
&&
1012 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
1013 qeth_l2_open(card
->dev
);
1016 dev_open(card
->dev
);
1019 /* this also sets saved unicast addresses */
1020 qeth_l2_set_multicast_list(card
->dev
);
1022 /* let user_space know that device is online */
1023 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
1026 card
->use_hard_stop
= 1;
1027 qeth_l2_stop_card(card
, 0);
1028 ccw_device_set_offline(CARD_DDEV(card
));
1029 ccw_device_set_offline(CARD_WDEV(card
));
1030 ccw_device_set_offline(CARD_RDEV(card
));
1031 if (recover_flag
== CARD_STATE_RECOVER
)
1032 card
->state
= CARD_STATE_RECOVER
;
1034 card
->state
= CARD_STATE_DOWN
;
1038 static int qeth_l2_set_online(struct ccwgroup_device
*gdev
)
1040 return __qeth_l2_set_online(gdev
, 0);
1043 static int __qeth_l2_set_offline(struct ccwgroup_device
*cgdev
,
1046 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
1047 int rc
= 0, rc2
= 0, rc3
= 0;
1048 enum qeth_card_states recover_flag
;
1050 QETH_DBF_TEXT(setup
, 3, "setoffl");
1051 QETH_DBF_HEX(setup
, 3, &card
, sizeof(void *));
1053 if (card
->dev
&& netif_carrier_ok(card
->dev
))
1054 netif_carrier_off(card
->dev
);
1055 recover_flag
= card
->state
;
1056 if (qeth_l2_stop_card(card
, recovery_mode
) == -ERESTARTSYS
) {
1057 PRINT_WARN("Stopping card %s interrupted by user!\n",
1059 return -ERESTARTSYS
;
1061 rc
= ccw_device_set_offline(CARD_DDEV(card
));
1062 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
1063 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
1065 rc
= (rc2
) ? rc2
: rc3
;
1067 QETH_DBF_TEXT_(setup
, 2, "1err%d", rc
);
1068 if (recover_flag
== CARD_STATE_UP
)
1069 card
->state
= CARD_STATE_RECOVER
;
1070 /* let user_space know that device is offline */
1071 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
1075 static int qeth_l2_set_offline(struct ccwgroup_device
*cgdev
)
1077 return __qeth_l2_set_offline(cgdev
, 0);
1080 static int qeth_l2_recover(void *ptr
)
1082 struct qeth_card
*card
;
1085 card
= (struct qeth_card
*) ptr
;
1086 QETH_DBF_TEXT(trace
, 2, "recover1");
1087 QETH_DBF_HEX(trace
, 2, &card
, sizeof(void *));
1088 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
1090 QETH_DBF_TEXT(trace
, 2, "recover2");
1091 PRINT_WARN("Recovery of device %s started ...\n",
1093 card
->use_hard_stop
= 1;
1094 __qeth_l2_set_offline(card
->gdev
, 1);
1095 rc
= __qeth_l2_set_online(card
->gdev
, 1);
1096 /* don't run another scheduled recovery */
1097 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1098 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
1100 PRINT_INFO("Device %s successfully recovered!\n",
1103 PRINT_INFO("Device %s could not be recovered!\n",
1108 static int __init
qeth_l2_init(void)
1110 PRINT_INFO("register layer 2 discipline\n");
1114 static void __exit
qeth_l2_exit(void)
1116 PRINT_INFO("unregister layer 2 discipline\n");
1119 static void qeth_l2_shutdown(struct ccwgroup_device
*gdev
)
1121 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1122 qeth_qdio_clear_card(card
, 0);
1123 qeth_clear_qdio_buffers(card
);
1126 struct ccwgroup_driver qeth_l2_ccwgroup_driver
= {
1127 .probe
= qeth_l2_probe_device
,
1128 .remove
= qeth_l2_remove_device
,
1129 .set_online
= qeth_l2_set_online
,
1130 .set_offline
= qeth_l2_set_offline
,
1131 .shutdown
= qeth_l2_shutdown
,
1133 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver
);
1135 static int qeth_osn_send_control_data(struct qeth_card
*card
, int len
,
1136 struct qeth_cmd_buffer
*iob
)
1138 unsigned long flags
;
1141 QETH_DBF_TEXT(trace
, 5, "osndctrd");
1143 wait_event(card
->wait_q
,
1144 atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1) == 0);
1145 qeth_prepare_control_data(card
, len
, iob
);
1146 QETH_DBF_TEXT(trace
, 6, "osnoirqp");
1147 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1148 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
1149 (addr_t
) iob
, 0, 0);
1150 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1152 PRINT_WARN("qeth_osn_send_control_data: "
1153 "ccw_device_start rc = %i\n", rc
);
1154 QETH_DBF_TEXT_(trace
, 2, " err%d", rc
);
1155 qeth_release_buffer(iob
->channel
, iob
);
1156 atomic_set(&card
->write
.irq_pending
, 0);
1157 wake_up(&card
->wait_q
);
1162 static int qeth_osn_send_ipa_cmd(struct qeth_card
*card
,
1163 struct qeth_cmd_buffer
*iob
, int data_len
)
1167 QETH_DBF_TEXT(trace
, 4, "osndipa");
1169 qeth_prepare_ipa_cmd(card
, iob
, QETH_PROT_OSN2
);
1170 s1
= (u16
)(IPA_PDU_HEADER_SIZE
+ data_len
);
1172 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
1173 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
1174 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
1175 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
1176 return qeth_osn_send_control_data(card
, s1
, iob
);
1179 int qeth_osn_assist(struct net_device
*dev
, void *data
, int data_len
)
1181 struct qeth_cmd_buffer
*iob
;
1182 struct qeth_card
*card
;
1185 QETH_DBF_TEXT(trace
, 2, "osnsdmc");
1188 card
= netdev_priv(dev
);
1191 if ((card
->state
!= CARD_STATE_UP
) &&
1192 (card
->state
!= CARD_STATE_SOFTSETUP
))
1194 iob
= qeth_wait_for_buffer(&card
->write
);
1195 memcpy(iob
->data
+IPA_PDU_HEADER_SIZE
, data
, data_len
);
1196 rc
= qeth_osn_send_ipa_cmd(card
, iob
, data_len
);
1199 EXPORT_SYMBOL(qeth_osn_assist
);
1201 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**dev
,
1202 int (*assist_cb
)(struct net_device
*, void *),
1203 int (*data_cb
)(struct sk_buff
*))
1205 struct qeth_card
*card
;
1207 QETH_DBF_TEXT(trace
, 2, "osnreg");
1208 *dev
= qeth_l2_netdev_by_devno(read_dev_no
);
1211 card
= netdev_priv(*dev
);
1214 if ((assist_cb
== NULL
) || (data_cb
== NULL
))
1216 card
->osn_info
.assist_cb
= assist_cb
;
1217 card
->osn_info
.data_cb
= data_cb
;
1220 EXPORT_SYMBOL(qeth_osn_register
);
1222 void qeth_osn_deregister(struct net_device
*dev
)
1224 struct qeth_card
*card
;
1226 QETH_DBF_TEXT(trace
, 2, "osndereg");
1229 card
= netdev_priv(dev
);
1232 card
->osn_info
.assist_cb
= NULL
;
1233 card
->osn_info
.data_cb
= NULL
;
1236 EXPORT_SYMBOL(qeth_osn_deregister
);
1238 module_init(qeth_l2_init
);
1239 module_exit(qeth_l2_exit
);
1240 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1241 MODULE_DESCRIPTION("qeth layer 2 discipline");
1242 MODULE_LICENSE("GPL");