9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
19 #include <linux/mii.h>
21 #include <linux/list.h>
33 static void qeth_l2_set_multicast_list(
struct net_device *);
34 static int qeth_l2_recover(
void *);
65 mii_data = if_mii(rq);
69 mii_data = if_mii(rq);
87 static int qeth_l2_verify_dev(
struct net_device *dev)
95 if (card->
dev == dev) {
105 static struct net_device *qeth_l2_netdev_by_devno(
unsigned char *read_dev_no)
114 memcpy(&temp_dev_no, read_dev_no, 2);
118 if (read_devid.devno == temp_dev_no) {
127 static int qeth_l2_send_setgroupmac_cb(
struct qeth_card *card,
141 cmd->
hdr.return_code = 0;
143 if (cmd->
hdr.return_code)
149 static int qeth_l2_send_setgroupmac(
struct qeth_card *card,
__u8 *mac)
153 qeth_l2_send_setgroupmac_cb);
156 static int qeth_l2_send_delgroupmac_cb(
struct qeth_card *card,
166 if (cmd->
hdr.return_code)
172 static int qeth_l2_send_delgroupmac(
struct qeth_card *card,
__u8 *mac)
176 qeth_l2_send_delgroupmac_cb);
179 static void qeth_l2_add_mc(
struct qeth_card *card,
__u8 *mac,
int vmac)
197 rc = qeth_l2_send_setgroupmac(card, mac);
206 static void qeth_l2_del_all_mc(
struct qeth_card *card,
int del)
210 spin_lock_bh(&card->
mclock);
214 qeth_l2_send_setdelmac(card, mc->
mc_addr,
217 qeth_l2_send_delgroupmac(card, mc->
mc_addr);
222 spin_unlock_bh(&card->
mclock);
225 static inline int qeth_l2_get_cast_type(
struct qeth_card *card,
230 if (is_broadcast_ether_addr(skb->
data))
232 if (is_multicast_ether_addr(skb->
data))
238 struct sk_buff *skb,
int ipv,
int cast_type)
263 static int qeth_l2_send_setdelvlan_cb(
struct qeth_card *card,
270 if (cmd->
hdr.return_code) {
291 qeth_l2_send_setdelvlan_cb,
NULL);
294 static void qeth_l2_process_vlans(
struct qeth_card *card)
305 static int qeth_l2_vlan_rx_add_vid(
struct net_device *dev,
unsigned short vid)
334 static int qeth_l2_vlan_rx_kill_vid(
struct net_device *dev,
unsigned short vid)
350 if (id->
vid == vid) {
361 qeth_l2_set_multicast_list(card->
dev);
365 static int qeth_l2_stop_card(
struct qeth_card *card,
int recovery_mode)
378 qeth_l2_stop(card->
dev);
388 qeth_l2_del_all_mc(card, 0);
405 static int qeth_l2_process_inbound_buffer(
struct qeth_card *card,
417 &card->
qdio.in_q->bufs[card->
rx.b_index],
418 &card->
rx.b_element, &card->
rx.e_offset, &hdr);
424 switch (hdr->
hdr.
l2.id) {
430 *((
__u32 *)skb->cb) = ++card->
seqno.pkt_seqno;
437 skb_copy_to_linear_data(skb, hdr,
452 card->
stats.rx_packets++;
453 card->
stats.rx_bytes += len;
464 int new_budget = budget;
466 if (card->
options.performance_stats) {
468 card->
perf_stats.inbound_start_time = qeth_get_micros();
472 if (!card->
rx.b_count) {
473 card->
rx.qdio_err = 0;
475 card->
data.ccwdev, 0, &card->
rx.b_index,
477 if (card->
rx.b_count <= 0) {
478 card->
rx.b_count = 0;
482 &card->
qdio.in_q->bufs[card->
rx.b_index]
484 card->
rx.e_offset = 0;
487 while (card->
rx.b_count) {
488 buffer = &card->
qdio.in_q->bufs[card->
rx.b_index];
489 if (!(card->
rx.qdio_err &&
491 card->
rx.qdio_err,
"qinerr")))
492 work_done += qeth_l2_process_inbound_buffer(
493 card, new_budget, &done);
498 if (card->
options.performance_stats)
500 qeth_put_buffer_pool_entry(card,
504 if (card->
rx.b_count) {
506 (card->
rx.b_index + 1) %
510 ->bufs[card->
rx.b_index]
512 card->
rx.e_offset = 0;
516 if (work_done >= budget)
519 new_budget = budget - work_done;
525 napi_schedule(&card->
napi);
527 if (card->
options.performance_stats)
528 card->
perf_stats.inbound_time += qeth_get_micros() -
533 static int qeth_l2_send_setdelmac(
struct qeth_card *card,
__u8 *mac,
550 static int qeth_l2_send_setmac_cb(
struct qeth_card *card,
558 if (cmd->
hdr.return_code) {
561 switch (cmd->
hdr.return_code) {
565 "MAC address %pM already exists\n",
571 "MAC address %pM is not authorized\n",
582 "MAC address %pM successfully registered on device %s\n",
583 card->
dev->dev_addr, card->
dev->name);
588 static int qeth_l2_send_setmac(
struct qeth_card *card,
__u8 *mac)
592 qeth_l2_send_setmac_cb);
595 static int qeth_l2_send_delmac_cb(
struct qeth_card *card,
603 if (cmd->
hdr.return_code) {
612 static int qeth_l2_send_delmac(
struct qeth_card *card,
__u8 *mac)
618 qeth_l2_send_delmac_cb);
621 static int qeth_l2_request_initial_mac(
struct qeth_card *card)
624 char vendor_pre[] = {0x02, 0x00, 0x00};
633 "parameters on device %s: x%x\n",
641 card->
info.guestlan) {
651 eth_random_addr(card->
dev->dev_addr);
652 memcpy(card->
dev->dev_addr, vendor_pre, 3);
657 static int qeth_l2_set_mac_address(
struct net_device *dev,
void *
p)
681 rc = qeth_l2_send_delmac(card, &card->
dev->dev_addr[0]);
683 rc = qeth_l2_send_setmac(card, addr->
sa_data);
687 static void qeth_l2_set_multicast_list(
struct net_device *dev)
699 qeth_l2_del_all_mc(card, 1);
700 spin_lock_bh(&card->
mclock);
702 qeth_l2_add_mc(card, ha->addr, 0);
705 qeth_l2_add_mc(card, ha->addr, 1);
707 spin_unlock_bh(&card->mclock);
720 int ipv = qeth_get_ip_version(skb);
721 int cast_type = qeth_l2_get_cast_type(card, skb);
726 int elements_needed = 0;
730 card->
stats.tx_carrier_errors++;
738 if (card->
options.performance_stats) {
740 card->
perf_stats.outbound_start_time = qeth_get_micros();
742 netif_stop_queue(dev);
756 skb_reset_mac_header(new_skb);
757 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
758 hdr->
hdr.
l2.pkt_length = new_skb->
len;
769 skb_set_mac_header(new_skb,
sizeof(
struct qeth_hdr));
770 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
777 if (data_offset >= 0)
790 elements, data_offset, hd_len);
792 card->
stats.tx_packets++;
798 if (data_offset >= 0)
809 netif_wake_queue(dev);
810 if (card->
options.performance_stats)
811 card->
perf_stats.outbound_time += qeth_get_micros() -
816 card->
stats.tx_dropped++;
817 card->
stats.tx_errors++;
818 if ((new_skb != skb) && new_skb)
821 netif_wake_queue(dev);
825 static int __qeth_l2_open(
struct net_device *dev)
843 netif_start_queue(dev);
846 napi_enable(&card->
napi);
847 napi_schedule(&card->
napi);
853 static int qeth_l2_open(
struct net_device *dev)
862 return __qeth_l2_open(dev);
865 static int qeth_l2_stop(
struct net_device *dev)
870 netif_tx_disable(dev);
873 napi_disable(&card->
napi);
883 INIT_LIST_HEAD(&card->
mc_list);
885 card->
info.hwtrap = 0;
896 if (cgdev->
state == CCWGROUP_ONLINE)
897 qeth_l2_set_offline(cgdev);
906 static const struct ethtool_ops qeth_l2_ethtool_ops = {
915 static const struct ethtool_ops qeth_l2_osn_ops = {
923 .ndo_open = qeth_l2_open,
924 .ndo_stop = qeth_l2_stop,
926 .ndo_start_xmit = qeth_l2_hard_start_xmit,
928 .ndo_set_rx_mode = qeth_l2_set_multicast_list,
929 .ndo_do_ioctl = qeth_l2_do_ioctl,
930 .ndo_set_mac_address = qeth_l2_set_mac_address,
932 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
933 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
937 static int qeth_l2_setup_netdev(
struct qeth_card *card)
939 switch (card->
info.type) {
948 card->
dev = alloc_etherdev(0);
956 card->
dev->mtu = card->
info.initial_mtu;
957 card->
dev->netdev_ops = &qeth_l2_netdev_ops;
963 card->
info.broadcast_capable = 1;
964 qeth_l2_request_initial_mac(card);
982 recover_flag = card->
state;
990 if (!card->
dev && qeth_l2_setup_netdev(card)) {
996 qeth_l2_send_setmac(card, &card->
dev->dev_addr[0]);
999 if (card->
info.hwtrap &&
1001 card->
info.hwtrap = 0;
1003 card->
info.hwtrap = 0;
1017 "The LAN is offline\n");
1034 qeth_l2_process_vlans(card);
1036 netif_tx_disable(card->
dev);
1052 if (recovery_mode &&
1054 __qeth_l2_open(card->
dev);
1061 qeth_l2_set_multicast_list(card->
dev);
1070 qeth_l2_stop_card(card, 0);
1085 return __qeth_l2_set_online(gdev, 0);
1092 int rc = 0, rc2 = 0, rc3 = 0;
1100 if (card->
dev && netif_carrier_ok(card->
dev))
1102 recover_flag = card->
state;
1103 if ((!recovery_mode && card->
info.hwtrap) || card->
info.hwtrap == 2) {
1105 card->
info.hwtrap = 1;
1107 qeth_l2_stop_card(card, recovery_mode);
1112 rc = (rc2) ? rc2 : rc3;
1126 return __qeth_l2_set_offline(cgdev, 0);
1129 static int qeth_l2_recover(
void *
ptr)
1140 "A recovery process has been started for the device\n");
1141 __qeth_l2_set_offline(card->
gdev, 1);
1142 rc = __qeth_l2_set_online(card->
gdev, 1);
1145 "Device successfully recovered!\n");
1151 "failed to recover an error on the device\n");
1159 static int __init qeth_l2_init(
void)
1161 pr_info(
"register layer 2 discipline\n");
1165 static void __exit qeth_l2_exit(
void)
1167 pr_info(
"unregister layer 2 discipline\n");
1174 if ((gdev->
state == CCWGROUP_ONLINE) && card->
info.hwtrap)
1188 if (gdev->
state == CCWGROUP_OFFLINE)
1191 if (card->
info.hwtrap)
1193 __qeth_l2_set_offline(card->
gdev, 1);
1195 __qeth_l2_set_offline(card->
gdev, 0);
1204 if (gdev->
state == CCWGROUP_OFFLINE)
1208 rc = __qeth_l2_set_online(card->
gdev, 1);
1215 rc = __qeth_l2_set_online(card->
gdev, 0);
1222 "failed to recover an error on the device\n");
1230 .recover = qeth_l2_recover,
1231 .setup = qeth_l2_probe_device,
1232 .remove = qeth_l2_remove_device,
1233 .set_online = qeth_l2_set_online,
1234 .set_offline = qeth_l2_set_offline,
1235 .shutdown = qeth_l2_shutdown,
1236 .freeze = qeth_l2_pm_suspend,
1237 .thaw = qeth_l2_pm_resume,
1238 .restore = qeth_l2_pm_resume,
1242 static int qeth_osn_send_control_data(
struct qeth_card *card,
int len,
1245 unsigned long flags;
1260 "ccw_device_start rc = %i\n", rc);
1269 static int qeth_osn_send_ipa_cmd(
struct qeth_card *card,
1283 return qeth_osn_send_control_data(card, s1, iob);
1303 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1309 int (*assist_cb)(
struct net_device *,
void *),
1310 int (*data_cb)(
struct sk_buff *))
1314 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1317 card = (*dev)->ml_priv;
1321 if ((assist_cb ==
NULL) || (data_cb ==
NULL))
1323 card->
osn_info.assist_cb = assist_cb;