Space.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * Holds initial configuration information for devices.
  8. *
  9. * Version: @(#)Space.c 1.0.7 08/12/93
  10. *
  11. * Authors: Ross Biro
  12. * Fred N. van Kempen, <[email protected]>
  13. * Donald J. Becker, <[email protected]>
  14. *
  15. * Changelog:
  16. * Stephen Hemminger (09/2003)
  17. * - get rid of pre-linked dev list, dynamic device allocation
  18. * Paul Gortmaker (03/2002)
  19. * - struct init cleanup, enable multiple ISA autoprobes.
  20. * Arnaldo Carvalho de Melo <[email protected]> - 09/1999
  21. * - fix sbni: s/device/net_device/
  22. * Paul Gortmaker (06/98):
  23. * - sort probes in a sane way, make sure all (safe) probes
  24. * get run once & failed autoprobes don't autoprobe again.
  25. */
  26. #include <linux/netdevice.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/errno.h>
  29. #include <linux/init.h>
  30. #include <linux/netlink.h>
  31. #include <net/Space.h>
  32. /*
  33. * This structure holds boot-time configured netdevice settings. They
  34. * are then used in the device probing.
  35. */
  36. struct netdev_boot_setup {
  37. char name[IFNAMSIZ];
  38. struct ifmap map;
  39. };
  40. #define NETDEV_BOOT_SETUP_MAX 8
  41. /******************************************************************************
  42. *
  43. * Device Boot-time Settings Routines
  44. *
  45. ******************************************************************************/
  46. /* Boot time configuration table */
  47. static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX];
  48. /**
  49. * netdev_boot_setup_add - add new setup entry
  50. * @name: name of the device
  51. * @map: configured settings for the device
  52. *
  53. * Adds new setup entry to the dev_boot_setup list. The function
  54. * returns 0 on error and 1 on success. This is a generic routine to
  55. * all netdevices.
  56. */
  57. static int netdev_boot_setup_add(char *name, struct ifmap *map)
  58. {
  59. struct netdev_boot_setup *s;
  60. int i;
  61. s = dev_boot_setup;
  62. for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
  63. if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
  64. memset(s[i].name, 0, sizeof(s[i].name));
  65. strscpy(s[i].name, name, IFNAMSIZ);
  66. memcpy(&s[i].map, map, sizeof(s[i].map));
  67. break;
  68. }
  69. }
  70. return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1;
  71. }
  72. /**
  73. * netdev_boot_setup_check - check boot time settings
  74. * @dev: the netdevice
  75. *
  76. * Check boot time settings for the device.
  77. * The found settings are set for the device to be used
  78. * later in the device probing.
  79. * Returns 0 if no settings found, 1 if they are.
  80. */
  81. int netdev_boot_setup_check(struct net_device *dev)
  82. {
  83. struct netdev_boot_setup *s = dev_boot_setup;
  84. int i;
  85. for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
  86. if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
  87. !strcmp(dev->name, s[i].name)) {
  88. dev->irq = s[i].map.irq;
  89. dev->base_addr = s[i].map.base_addr;
  90. dev->mem_start = s[i].map.mem_start;
  91. dev->mem_end = s[i].map.mem_end;
  92. return 1;
  93. }
  94. }
  95. return 0;
  96. }
  97. EXPORT_SYMBOL(netdev_boot_setup_check);
  98. /**
  99. * netdev_boot_base - get address from boot time settings
  100. * @prefix: prefix for network device
  101. * @unit: id for network device
  102. *
  103. * Check boot time settings for the base address of device.
  104. * The found settings are set for the device to be used
  105. * later in the device probing.
  106. * Returns 0 if no settings found.
  107. */
  108. static unsigned long netdev_boot_base(const char *prefix, int unit)
  109. {
  110. const struct netdev_boot_setup *s = dev_boot_setup;
  111. char name[IFNAMSIZ];
  112. int i;
  113. sprintf(name, "%s%d", prefix, unit);
  114. /*
  115. * If device already registered then return base of 1
  116. * to indicate not to probe for this interface
  117. */
  118. if (__dev_get_by_name(&init_net, name))
  119. return 1;
  120. for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
  121. if (!strcmp(name, s[i].name))
  122. return s[i].map.base_addr;
  123. return 0;
  124. }
  125. /*
  126. * Saves at boot time configured settings for any netdevice.
  127. */
  128. static int __init netdev_boot_setup(char *str)
  129. {
  130. int ints[5];
  131. struct ifmap map;
  132. str = get_options(str, ARRAY_SIZE(ints), ints);
  133. if (!str || !*str)
  134. return 0;
  135. /* Save settings */
  136. memset(&map, 0, sizeof(map));
  137. if (ints[0] > 0)
  138. map.irq = ints[1];
  139. if (ints[0] > 1)
  140. map.base_addr = ints[2];
  141. if (ints[0] > 2)
  142. map.mem_start = ints[3];
  143. if (ints[0] > 3)
  144. map.mem_end = ints[4];
  145. /* Add new entry to the list */
  146. return netdev_boot_setup_add(str, &map);
  147. }
  148. __setup("netdev=", netdev_boot_setup);
  149. static int __init ether_boot_setup(char *str)
  150. {
  151. return netdev_boot_setup(str);
  152. }
  153. __setup("ether=", ether_boot_setup);
  154. /* A unified ethernet device probe. This is the easiest way to have every
  155. * ethernet adaptor have the name "eth[0123...]".
  156. */
  157. struct devprobe2 {
  158. struct net_device *(*probe)(int unit);
  159. int status; /* non-zero if autoprobe has failed */
  160. };
  161. static int __init probe_list2(int unit, struct devprobe2 *p, int autoprobe)
  162. {
  163. struct net_device *dev;
  164. for (; p->probe; p++) {
  165. if (autoprobe && p->status)
  166. continue;
  167. dev = p->probe(unit);
  168. if (!IS_ERR(dev))
  169. return 0;
  170. if (autoprobe)
  171. p->status = PTR_ERR(dev);
  172. }
  173. return -ENODEV;
  174. }
  175. /* ISA probes that touch addresses < 0x400 (including those that also
  176. * look for EISA/PCI cards in addition to ISA cards).
  177. */
  178. static struct devprobe2 isa_probes[] __initdata = {
  179. #ifdef CONFIG_3C515
  180. {tc515_probe, 0},
  181. #endif
  182. #ifdef CONFIG_ULTRA
  183. {ultra_probe, 0},
  184. #endif
  185. #ifdef CONFIG_WD80x3
  186. {wd_probe, 0},
  187. #endif
  188. #if defined(CONFIG_NE2000) /* ISA (use ne2k-pci for PCI cards) */
  189. {ne_probe, 0},
  190. #endif
  191. #ifdef CONFIG_LANCE /* ISA/VLB (use pcnet32 for PCI cards) */
  192. {lance_probe, 0},
  193. #endif
  194. #ifdef CONFIG_SMC9194
  195. {smc_init, 0},
  196. #endif
  197. #ifdef CONFIG_CS89x0_ISA
  198. {cs89x0_probe, 0},
  199. #endif
  200. {NULL, 0},
  201. };
  202. /* Unified ethernet device probe, segmented per architecture and
  203. * per bus interface. This drives the legacy devices only for now.
  204. */
  205. static void __init ethif_probe2(int unit)
  206. {
  207. unsigned long base_addr = netdev_boot_base("eth", unit);
  208. if (base_addr == 1)
  209. return;
  210. probe_list2(unit, isa_probes, base_addr == 0);
  211. }
  212. /* Statically configured drivers -- order matters here. */
  213. static int __init net_olddevs_init(void)
  214. {
  215. int num;
  216. for (num = 0; num < 8; ++num)
  217. ethif_probe2(num);
  218. #ifdef CONFIG_COPS
  219. cops_probe(0);
  220. cops_probe(1);
  221. cops_probe(2);
  222. #endif
  223. return 0;
  224. }
  225. device_initcall(net_olddevs_init);