26 #define KMSG_COMPONENT "lcs"
27 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
29 #include <linux/module.h>
31 #include <linux/netdevice.h>
36 #include <linux/igmp.h>
39 #include <linux/slab.h>
43 #include <asm/debug.h>
45 #include <asm/timex.h>
46 #include <linux/device.h>
52 #if !defined(CONFIG_ETHERNET) && !defined(CONFIG_FDDI)
53 #error Cannot compile lcs.c without some net devices switched on.
65 static struct device *lcs_root_dev;
70 static void lcs_tasklet(
unsigned long);
71 static void lcs_start_kernel_thread(
struct work_struct *);
73 #ifdef CONFIG_IP_MULTICAST
76 static int lcs_recovery(
void *
ptr);
89 lcs_unregister_debug_facility(
void)
98 lcs_register_debug_facility(
void)
102 if (lcs_dbf_setup ==
NULL || lcs_dbf_trace ==
NULL) {
103 pr_err(
"Not enough memory for debug facility.\n");
104 lcs_unregister_debug_facility();
127 if (channel->
iob[cnt].data ==
NULL)
131 if (cnt < LCS_NUM_BUFFS) {
166 lcs_free_channel(channel);
198 rc = lcs_alloc_channel(&card->
read);
205 rc = lcs_alloc_channel(&card->
write);
208 lcs_cleanup_channel(&card->
read);
213 #ifdef CONFIG_IP_MULTICAST
214 INIT_LIST_HEAD(&card->ipm_list);
224 lcs_setup_read_ccws(
struct lcs_card *card)
244 card->
read.iob[
cnt].callback = lcs_get_frames_cb;
258 card->
read.io_idx = 0;
259 card->
read.buf_idx = 0;
263 lcs_setup_read(
struct lcs_card *card)
267 lcs_setup_read_ccws(card);
269 card->
read.irq_tasklet.data = (
unsigned long) &card->
read;
270 card->
read.irq_tasklet.func = lcs_tasklet;
279 lcs_setup_write_ccws(
struct lcs_card *card)
285 memset(card->
write.ccws, 0,
sizeof(
struct ccw1) * (LCS_NUM_BUFFS + 1));
305 card->
write.io_idx = 0;
306 card->
write.buf_idx = 0;
310 lcs_setup_write(
struct lcs_card *card)
314 lcs_setup_write_ccws(card);
317 card->
write.irq_tasklet.func = lcs_tasklet;
329 spin_unlock_irqrestore(&card->
mask_lock, flags);
340 spin_unlock_irqrestore(&card->
mask_lock, flags);
348 lcs_threads_running(card, threads) == 0);
352 lcs_set_thread_start_bit(
struct lcs_card *card,
unsigned long thread)
359 spin_unlock_irqrestore(&card->
mask_lock, flags);
363 spin_unlock_irqrestore(&card->
mask_lock, flags);
368 lcs_clear_thread_running_bit(
struct lcs_card *card,
unsigned long thread)
374 spin_unlock_irqrestore(&card->
mask_lock, flags);
379 __lcs_do_run_thread(
struct lcs_card *card,
unsigned long thread)
394 spin_unlock_irqrestore(&card->
mask_lock, flags);
399 lcs_do_run_thread(
struct lcs_card *card,
unsigned long thread)
403 (rc = __lcs_do_run_thread(card, thread)) >= 0);
408 lcs_do_start_thread(
struct lcs_card *card,
unsigned long thread)
419 spin_unlock_irqrestore(&card->
mask_lock, flags);
427 lcs_setup_card(
struct lcs_card *card)
432 lcs_setup_read(card);
433 lcs_setup_write(card);
443 #ifdef CONFIG_IP_MULTICAST
444 INIT_LIST_HEAD(&card->ipm_list);
450 lcs_clear_multicast_list(
struct lcs_card *card)
452 #ifdef CONFIG_IP_MULTICAST
459 while (!list_empty(&card->ipm_list)){
464 spin_unlock_irqrestore(&card->
ipm_lock, flags);
465 lcs_send_delipm(card, ipm);
470 spin_unlock_irqrestore(&card->
ipm_lock, flags);
477 lcs_cleanup_card(
struct lcs_card *card)
486 lcs_cleanup_channel(&card->
write);
487 lcs_cleanup_channel(&card->
read);
509 dev_name(&channel->
ccwdev->dev));
511 "Starting an LCS device resulted in an error,"
530 dev_name(&channel->
ccwdev->dev));
558 dev_name(&channel->
ccwdev->dev));
563 lcs_clear_channel(channel);
571 lcs_start_channels(
struct lcs_card *card)
577 rc = lcs_start_channel(&card->
read);
581 rc = lcs_start_channel(&card->
write);
583 lcs_stop_channel(&card->
read);
591 lcs_stop_channels(
struct lcs_card *card)
594 lcs_stop_channel(&card->
read);
595 lcs_stop_channel(&card->
write);
614 index = (index + 1) & (LCS_NUM_BUFFS - 1);
615 }
while (index != channel->
io_idx);
627 buffer = __lcs_get_buffer(channel);
648 dev_name(&channel->
ccwdev->dev));
650 "Sending data from the LCS device to the LAN failed"
662 __lcs_ready_buffer_bits(
struct lcs_channel *channel,
int index)
667 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
668 next = (index + 1) & (LCS_NUM_BUFFS - 1);
672 if (!(channel->
ccws[prev].flags & CCW_FLAG_SUSPEND))
676 channel->
ccws[index].flags &= ~CCW_FLAG_SUSPEND;
691 index = buffer - channel->
iob;
695 __lcs_ready_buffer_bits(channel, index);
696 rc = __lcs_resume_channel(channel);
714 index = buffer - channel->
iob;
715 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
716 next = (index + 1) & (LCS_NUM_BUFFS - 1);
728 __lcs_ready_buffer_bits(channel, prev);
732 return __lcs_resume_channel(channel);
763 ((buffer = lcs_get_buffer(&card->
write)) !=
NULL));
767 buffer->
callback = lcs_release_buffer;
794 lcs_alloc_reply(
struct lcs_cmd *cmd)
822 spin_lock(&card->
lock);
826 lcs_get_reply(reply);
827 list_del_init(&reply->
list);
833 lcs_put_reply(reply);
837 spin_unlock(&card->
lock);
844 lcs_lancmd_timeout(
unsigned long data)
853 &reply->
card->lancmd_waiters,
list) {
854 if (reply == list_reply) {
855 lcs_get_reply(reply);
856 list_del_init(&reply->
list);
857 spin_unlock_irqrestore(&reply->
card->lock, flags);
861 lcs_put_reply(reply);
865 spin_unlock_irqrestore(&reply->
card->lock, flags);
882 reply = lcs_alloc_reply(cmd);
889 spin_unlock_irqrestore(&card->
lock, flags);
891 buffer->
callback = lcs_release_buffer;
892 rc = lcs_ready_buffer(&card->
write, buffer);
896 timer.function = lcs_lancmd_timeout;
904 lcs_put_reply(reply);
905 return rc ? -
EIO : 0;
923 return lcs_send_lancmd(card, buffer,
NULL);
930 lcs_send_shutdown(
struct lcs_card *card)
940 return lcs_send_lancmd(card, buffer,
NULL);
954 lcs_send_lanstat(
struct lcs_card *card)
967 return lcs_send_lancmd(card, buffer, __lcs_lanstat_cb);
986 return lcs_send_lancmd(card, buffer,
NULL);
1001 lcs_send_startlan(
struct lcs_card *card,
__u8 initiator)
1013 return lcs_send_lancmd(card, buffer, __lcs_send_startlan_cb);
1016 #ifdef CONFIG_IP_MULTICAST
1033 cmd->cmd.lcs_qipassist.version = 4;
1034 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1035 memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
1038 return lcs_send_lancmd(card, buffer,
NULL);
1057 cmd->cmd.lcs_qipassist.version = 4;
1058 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1059 memcpy(cmd->cmd.lcs_qipassist.lcs_ipass_ctlmsg.ip_mac_pair,
1062 return lcs_send_lancmd(card, buffer,
NULL);
1073 cmd->cmd.lcs_qipassist.ip_assists_supported;
1075 cmd->cmd.lcs_qipassist.ip_assists_enabled;
1079 lcs_check_multicast_support(
struct lcs_card *card)
1093 cmd->cmd.lcs_qipassist.version = 4;
1094 cmd->cmd.lcs_qipassist.num_ip_pairs = 1;
1095 rc = lcs_send_lancmd(card, buffer, __lcs_check_multicast_cb);
1097 pr_err(
"Query IPAssist failed. Assuming unsupported!\n");
1109 lcs_fix_multicast_list(
struct lcs_card *card)
1113 unsigned long flags;
1117 INIT_LIST_HEAD(&failed_list);
1125 list_del_init(&ipm->
list);
1126 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1127 rc = lcs_send_setipm(card, ipm);
1130 pr_info(
"Adding multicast address failed."
1131 " Table possibly full!\n");
1144 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1145 lcs_send_delipm(card, ipm);
1155 list_move_tail(&ipm->
list, &card->ipm_list);
1157 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1167 ip_eth_mc_map(ipm, mac);
1174 lcs_remove_mc_addresses(
struct lcs_card *card,
struct in_device *in4_dev)
1179 unsigned long flags;
1197 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1205 unsigned long flags;
1218 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1223 lcs_set_mc_addresses(
struct lcs_card *card,
struct in_device *in4_dev)
1229 unsigned long flags;
1235 ipm = lcs_check_addr_entry(card, im4, buf);
1240 pr_info(
"Not enough memory to add"
1241 " new multicast entry!\n");
1249 list_add(&ipm->
list, &card->ipm_list);
1250 spin_unlock_irqrestore(&card->
ipm_lock, flags);
1255 lcs_register_mc_addresses(
void *data)
1258 struct in_device *in4_dev;
1266 in4_dev = in_dev_get(card->
dev);
1267 if (in4_dev ==
NULL)
1270 lcs_remove_mc_addresses(card,in4_dev);
1271 lcs_set_mc_addresses(card, in4_dev);
1273 in_dev_put(in4_dev);
1276 netif_tx_disable(card->
dev);
1279 lcs_fix_multicast_list(card);
1282 netif_wake_queue(card->
dev);
1297 #ifdef CONFIG_IP_MULTICAST
1314 switch (PTR_ERR(irb)) {
1317 "An I/O-error occurred on the LCS device\n");
1323 "A command timed out on the LCS device\n");
1329 "An error occurred on the LCS device, rc=%ld\n",
1334 return PTR_ERR(irb);
1338 lcs_get_problem(
struct ccw_device *cdev,
struct irb *irb)
1343 sense = (
char *) irb->
ecw;
1378 lcs_schedule_recovery(
struct lcs_card *card)
1396 if (lcs_check_irb_error(cdev, irb))
1400 if (card->
read.ccwdev == cdev)
1401 channel = &card->
read;
1403 channel = &card->
write;
1414 rc = lcs_get_problem(cdev, irb);
1417 "The LCS device stopped because of an error,"
1418 " dstat=0x%X, cstat=0x%X \n",
1425 lcs_schedule_recovery(card);
1438 index = (index - 1) & (LCS_NUM_BUFFS - 1);
1439 while (channel->
io_idx != index) {
1440 __lcs_processed_buffer(channel,
1443 (channel->
io_idx + 1) & (LCS_NUM_BUFFS - 1);
1449 (irb->
scsw.
cmd.dstat & DEV_STAT_UNIT_CHECK))
1473 lcs_tasklet(
unsigned long data)
1475 unsigned long flags;
1490 buf_idx = (buf_idx + 1) & (LCS_NUM_BUFFS - 1);
1495 lcs_start_channel(channel);
1499 __lcs_resume_channel(channel);
1510 __lcs_emit_txbuffer(
struct lcs_card *card)
1530 lcs_release_buffer(channel, buffer);
1532 if (netif_queue_stopped(card->
dev) && netif_carrier_ok(card->
dev))
1533 netif_wake_queue(card->
dev);
1534 spin_lock(&card->
lock);
1541 __lcs_emit_txbuffer(card);
1542 spin_unlock(&card->
lock);
1557 card->
stats.tx_dropped++;
1558 card->
stats.tx_errors++;
1563 card->
stats.tx_dropped++;
1564 card->
stats.tx_errors++;
1565 card->
stats.tx_carrier_errors++;
1572 netif_stop_queue(card->
dev);
1573 spin_lock(&card->
lock);
1578 __lcs_emit_txbuffer(card);
1583 card->
stats.tx_dropped++;
1587 card->
tx_buffer->callback = lcs_txbuffer_cb;
1596 skb_copy_from_linear_data(skb, header + 1, skb->
len);
1597 spin_unlock(&card->
lock);
1599 card->
stats.tx_packets++;
1601 netif_wake_queue(card->
dev);
1602 spin_lock(&card->
lock);
1605 __lcs_emit_txbuffer(card);
1607 spin_unlock(&card->
lock);
1619 rc = __lcs_start_xmit(card, skb, dev);
1627 lcs_startlan_auto(
struct lcs_card *card)
1632 #ifdef CONFIG_ETHERNET
1649 lcs_startlan(
struct lcs_card *card)
1657 rc = lcs_startlan_auto(card);
1661 for (i = 0; i <= 16; i++) {
1664 rc = lcs_send_startlan(card,
1668 rc = lcs_startlan_auto(card);
1674 return lcs_send_lanstat(card);
1690 netif_stop_queue(card->
dev);
1691 rc = lcs_stop_channels(card);
1693 rc = lcs_start_channels(card);
1697 rc = lcs_startlan(card);
1714 lcs_stopcard(
struct lcs_card *card)
1725 lcs_clear_multicast_list(card);
1727 rc = lcs_send_shutdown(card);
1729 rc = lcs_stop_channels(card);
1745 #ifdef CONFIG_IP_MULTICAST
1747 kthread_run(lcs_register_mc_addresses, card,
"regipm");
1762 lcs_schedule_recovery(card);
1765 pr_warning(
"Stoplan for %s initiated by LGW.\n",
1775 lcs_notify_lancmd_waiters(card, cmd);
1792 skb = dev_alloc_skb(skb_len);
1795 " Allocating a socket buffer to interface %s failed\n",
1797 card->
stats.rx_dropped++;
1802 card->
stats.rx_bytes += skb_len;
1803 card->
stats.rx_packets++;
1827 while (lcs_hdr->
offset != 0) {
1828 if (lcs_hdr->
offset <= 0 ||
1830 lcs_hdr->
offset < offset) {
1832 card->
stats.rx_length_errors++;
1833 card->
stats.rx_errors++;
1839 lcs_get_control(card, (
struct lcs_cmd *) lcs_hdr);
1844 lcs_get_skb(card, (
char *)(lcs_hdr + 1),
1845 lcs_hdr->
offset - offset -
1851 offset = lcs_hdr->
offset;
1856 lcs_ready_buffer(&card->
read, buffer);
1869 return &card->
stats;
1885 netif_tx_disable(dev);
1889 rc = lcs_stopcard(card);
1892 " Shutting down the LCS device failed\n ");
1909 rc = lcs_detect(card);
1911 pr_err(
"Error in opening device!\n");
1916 netif_wake_queue(dev);
1952 sscanf(buf,
"%u", &value);
1962 static const char *lcs_type[] = {
1967 "unknown channel type",
1968 "unsupported channel type",
1980 return sprintf(buf,
"%s\n", lcs_type[cgdev->
cdev[0]->id.driver_info]);
2006 sscanf(buf,
"%u", &value);
2018 const char *buf,
size_t count)
2030 lcs_schedule_recovery(card);
2036 static struct attribute * lcs_attrs[] = {
2037 &dev_attr_portno.attr,
2038 &dev_attr_type.attr,
2039 &dev_attr_lancmd_timeout.attr,
2040 &dev_attr_recover.attr,
2052 .groups = lcs_attr_groups,
2067 card = lcs_alloc_card();
2074 ccwgdev->
cdev[0]->handler = lcs_irq;
2075 ccwgdev->
cdev[1]->handler = lcs_irq;
2076 card->
gdev = ccwgdev;
2081 ccwgdev->
dev.type = &lcs_devtype;
2093 if (card->
dev->reg_state != NETREG_UNINITIALIZED)
2103 .ndo_open = lcs_open_device,
2104 .ndo_stop = lcs_stop_device,
2105 .ndo_get_stats = lcs_getstats,
2106 .ndo_start_xmit = lcs_start_xmit,
2110 .ndo_open = lcs_open_device,
2111 .ndo_stop = lcs_stop_device,
2112 .ndo_get_stats = lcs_getstats,
2113 .ndo_start_xmit = lcs_start_xmit,
2114 .ndo_set_rx_mode = lcs_set_multicast_list,
2131 card->
read.ccwdev = ccwgdev->
cdev[0];
2134 recover_state = card->
state;
2144 lcs_setup_card(card);
2145 rc = lcs_detect(card);
2149 "Detecting a network adapter for LCS devices"
2150 " failed with rc=%d (0x%x)\n", rc, rc);
2160 #ifdef CONFIG_ETHERNET
2163 dev = alloc_etherdev(0);
2174 pr_err(
" Initialization failed\n");
2181 card->
dev->netdev_ops = &lcs_netdev_ops;
2183 #ifdef CONFIG_IP_MULTICAST
2184 if (!lcs_check_multicast_support(card))
2185 card->
dev->netdev_ops = &lcs_mc_netdev_ops;
2188 lcs_set_allowed_threads(card,0xffffffff);
2190 lcs_set_multicast_list(card->
dev);
2193 netif_wake_queue(card->
dev);
2199 if (lcs_register_netdev(ccwgdev) != 0)
2203 pr_info(
"LCS device %s %s IPv6 support\n", card->
dev->name,
2205 "with" :
"without");
2207 pr_info(
"LCS device %s %s Multicast support\n", card->
dev->name,
2209 "with" :
"without");
2224 __lcs_shutdown_device(
struct ccwgroup_device *ccwgdev,
int recovery_mode)
2228 int ret = 0, ret2 = 0, ret3 = 0;
2234 if (recovery_mode == 0) {
2235 lcs_set_allowed_threads(card, 0);
2240 recover_state = card->
state;
2242 ret = lcs_stop_device(card->
dev);
2246 ret = (ret2) ? ret2 : ret3;
2258 return __lcs_shutdown_device(ccwgdev, 0);
2265 lcs_recovery(
void *
ptr)
2279 "A recovery process has been started for the LCS device\n");
2280 rc = __lcs_shutdown_device(gdev, 1);
2281 rc = lcs_new_device(gdev);
2283 pr_info(
"Device %s successfully recovered!\n",
2286 pr_info(
"Device %s could not be recovered!\n",
2306 if (ccwgdev->
state == CCWGROUP_ONLINE) {
2307 lcs_shutdown_device(ccwgdev);
2311 lcs_cleanup_card(card);
2312 lcs_free_card(card);
2317 static int lcs_pm_suspend(
struct lcs_card *card)
2321 lcs_set_allowed_threads(card, 0);
2322 lcs_wait_for_threads(card, 0xffffffff);
2324 __lcs_shutdown_device(card->
gdev, 1);
2328 static int lcs_pm_resume(
struct lcs_card *card)
2333 rc = lcs_new_device(card->
gdev);
2338 "failed to recover the device\n");
2356 return lcs_pm_suspend(card);
2362 return lcs_pm_resume(card);
2368 return lcs_pm_resume(card);
2398 .setup = lcs_probe_device,
2399 .remove = lcs_remove_device,
2400 .set_online = lcs_new_device,
2401 .set_offline = lcs_shutdown_device,
2402 .prepare = lcs_prepare,
2403 .complete = lcs_complete,
2404 .freeze = lcs_freeze,
2406 .restore = lcs_restore,
2410 const char *buf,
size_t count)
2414 return err ? err :
count;
2418 static struct attribute *lcs_drv_attrs[] = {
2419 &driver_attr_group.attr,
2423 .attrs = lcs_drv_attrs,
2426 &lcs_drv_attr_group,
2434 __init lcs_init_module(
void)
2439 rc = lcs_register_debug_facility();
2444 rc = IS_ERR(lcs_root_dev) ? PTR_ERR(lcs_root_dev) : 0;
2450 lcs_group_driver.
driver.groups = lcs_drv_attr_groups;
2461 lcs_unregister_debug_facility();
2463 pr_err(
"Initializing the lcs device driver failed\n");
2472 __exit lcs_cleanup_module(
void)
2474 pr_info(
"Terminating lcs module.\n");
2479 lcs_unregister_debug_facility();