Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

e1000.c 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /*
  2. * gPXE driver for Intel eepro1000 ethernet cards
  3. *
  4. * Written by Marty Connor
  5. *
  6. * Copyright Entity Cyber, Inc. 2007
  7. *
  8. * This software may be used and distributed according to the terms of
  9. * the GNU General Public License (GPL), incorporated herein by
  10. * reference. Drivers based on or derived from this code fall under
  11. * the GPL and must retain the authorship, copyright and license
  12. * notice.
  13. *
  14. */
  15. /*******************************************************************************
  16. Intel PRO/1000 Linux driver
  17. Copyright(c) 1999 - 2006 Intel Corporation.
  18. This program is free software; you can redistribute it and/or modify it
  19. under the terms and conditions of the GNU General Public License,
  20. version 2, as published by the Free Software Foundation.
  21. This program is distributed in the hope it will be useful, but WITHOUT
  22. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  23. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  24. more details.
  25. You should have received a copy of the GNU General Public License along with
  26. this program; if not, write to the Free Software Foundation, Inc.,
  27. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  28. The full GNU General Public License is included in this distribution in
  29. the file called "COPYING".
  30. Contact Information:
  31. Linux NICS <linux.nics@intel.com>
  32. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  33. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  34. *******************************************************************************/
  35. FILE_LICENCE ( GPL2_ONLY );
  36. #include "e1000.h"
  37. /**
  38. * e1000_get_hw_control - get control of the h/w from f/w
  39. *
  40. * @v adapter e1000 private structure
  41. *
  42. * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  43. * For ASF and Pass Through versions of f/w this means that
  44. * the driver is loaded. For AMT version (only with 82573)
  45. * of the f/w this means that the network i/f is open.
  46. *
  47. **/
  48. static void
  49. e1000_get_hw_control ( struct e1000_adapter *adapter )
  50. {
  51. uint32_t ctrl_ext;
  52. uint32_t swsm;
  53. DBG ( "e1000_get_hw_control\n" );
  54. /* Let firmware know the driver has taken over */
  55. switch (adapter->hw.mac_type) {
  56. case e1000_82573:
  57. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  58. E1000_WRITE_REG(&adapter->hw, SWSM,
  59. swsm | E1000_SWSM_DRV_LOAD);
  60. break;
  61. case e1000_82571:
  62. case e1000_82572:
  63. case e1000_80003es2lan:
  64. case e1000_ich8lan:
  65. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  66. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  67. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. /**
  74. * e1000_irq_enable - Enable default interrupt generation settings
  75. *
  76. * @v adapter e1000 private structure
  77. **/
  78. static void
  79. e1000_irq_enable ( struct e1000_adapter *adapter )
  80. {
  81. E1000_WRITE_REG ( &adapter->hw, IMS, E1000_IMS_RXDMT0 |
  82. E1000_IMS_RXSEQ );
  83. E1000_WRITE_FLUSH ( &adapter->hw );
  84. }
  85. /**
  86. * e1000_irq_disable - Mask off interrupt generation on the NIC
  87. *
  88. * @v adapter e1000 private structure
  89. **/
  90. static void
  91. e1000_irq_disable ( struct e1000_adapter *adapter )
  92. {
  93. E1000_WRITE_REG ( &adapter->hw, IMC, ~0 );
  94. E1000_WRITE_FLUSH ( &adapter->hw );
  95. }
  96. /**
  97. * e1000_irq_force - trigger interrupt
  98. *
  99. * @v adapter e1000 private structure
  100. **/
  101. static void
  102. e1000_irq_force ( struct e1000_adapter *adapter )
  103. {
  104. E1000_WRITE_REG ( &adapter->hw, ICS, E1000_ICS_RXDMT0 );
  105. E1000_WRITE_FLUSH ( &adapter->hw );
  106. }
  107. /**
  108. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  109. *
  110. * @v adapter e1000 private structure
  111. *
  112. * e1000_sw_init initializes the Adapter private data structure.
  113. * Fields are initialized based on PCI device information and
  114. * OS network device settings (MTU size).
  115. **/
  116. static int
  117. e1000_sw_init ( struct e1000_adapter *adapter )
  118. {
  119. struct e1000_hw *hw = &adapter->hw;
  120. struct pci_device *pdev = adapter->pdev;
  121. /* PCI config space info */
  122. hw->vendor_id = pdev->vendor;
  123. hw->device_id = pdev->device;
  124. pci_read_config_word ( pdev, PCI_COMMAND, &hw->pci_cmd_word );
  125. /* Disable Flow Control */
  126. hw->fc = E1000_FC_NONE;
  127. adapter->eeprom_wol = 0;
  128. adapter->wol = adapter->eeprom_wol;
  129. adapter->en_mng_pt = 0;
  130. adapter->rx_int_delay = 0;
  131. adapter->rx_abs_int_delay = 0;
  132. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  133. adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
  134. hw->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE +
  135. ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  136. hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
  137. /* identify the MAC */
  138. if ( e1000_set_mac_type ( hw ) ) {
  139. DBG ( "Unknown MAC Type\n" );
  140. return -EIO;
  141. }
  142. switch ( hw->mac_type ) {
  143. default:
  144. break;
  145. case e1000_82541:
  146. case e1000_82547:
  147. case e1000_82541_rev_2:
  148. case e1000_82547_rev_2:
  149. hw->phy_init_script = 1;
  150. break;
  151. }
  152. e1000_set_media_type ( hw );
  153. hw->autoneg = TRUE;
  154. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  155. hw->wait_autoneg_complete = TRUE;
  156. hw->tbi_compatibility_en = TRUE;
  157. hw->adaptive_ifs = TRUE;
  158. /* Copper options */
  159. if ( hw->media_type == e1000_media_type_copper ) {
  160. hw->mdix = AUTO_ALL_MODES;
  161. hw->disable_polarity_correction = FALSE;
  162. hw->master_slave = E1000_MASTER_SLAVE;
  163. }
  164. e1000_irq_disable ( adapter );
  165. return 0;
  166. }
  167. /**
  168. * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
  169. *
  170. * @v adapter e1000 private structure
  171. *
  172. * @ret rc Returns 0 on success, negative on failure
  173. **/
  174. static int
  175. e1000_setup_tx_resources ( struct e1000_adapter *adapter )
  176. {
  177. DBG ( "e1000_setup_tx_resources\n" );
  178. /* Allocate transmit descriptor ring memory.
  179. It must not cross a 64K boundary because of hardware errata #23
  180. so we use malloc_dma() requesting a 128 byte block that is
  181. 128 byte aligned. This should guarantee that the memory
  182. allocated will not cross a 64K boundary, because 128 is an
  183. even multiple of 65536 ( 65536 / 128 == 512 ), so all possible
  184. allocations of 128 bytes on a 128 byte boundary will not
  185. cross 64K bytes.
  186. */
  187. adapter->tx_base =
  188. malloc_dma ( adapter->tx_ring_size, adapter->tx_ring_size );
  189. if ( ! adapter->tx_base ) {
  190. return -ENOMEM;
  191. }
  192. memset ( adapter->tx_base, 0, adapter->tx_ring_size );
  193. DBG ( "adapter->tx_base = %#08lx\n", virt_to_bus ( adapter->tx_base ) );
  194. return 0;
  195. }
  196. static void
  197. e1000_free_tx_resources ( struct e1000_adapter *adapter )
  198. {
  199. DBG ( "e1000_free_tx_resources\n" );
  200. free_dma ( adapter->tx_base, adapter->tx_ring_size );
  201. }
  202. /**
  203. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  204. * @adapter: board private structure
  205. *
  206. * Configure the Tx unit of the MAC after a reset.
  207. **/
  208. static void
  209. e1000_configure_tx ( struct e1000_adapter *adapter )
  210. {
  211. struct e1000_hw *hw = &adapter->hw;
  212. uint32_t tctl;
  213. DBG ( "e1000_configure_tx\n" );
  214. E1000_WRITE_REG ( hw, TDBAH, 0 );
  215. E1000_WRITE_REG ( hw, TDBAL, virt_to_bus ( adapter->tx_base ) );
  216. E1000_WRITE_REG ( hw, TDLEN, adapter->tx_ring_size );
  217. DBG ( "TDBAL: %#08x\n", E1000_READ_REG ( hw, TDBAL ) );
  218. DBG ( "TDLEN: %d\n", E1000_READ_REG ( hw, TDLEN ) );
  219. /* Setup the HW Tx Head and Tail descriptor pointers */
  220. E1000_WRITE_REG ( hw, TDH, 0 );
  221. E1000_WRITE_REG ( hw, TDT, 0 );
  222. adapter->tx_head = 0;
  223. adapter->tx_tail = 0;
  224. adapter->tx_fill_ctr = 0;
  225. /* Setup Transmit Descriptor Settings for eop descriptor */
  226. tctl = E1000_TCTL_PSP | E1000_TCTL_EN |
  227. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT) |
  228. (E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
  229. e1000_config_collision_dist ( hw );
  230. E1000_WRITE_REG ( hw, TCTL, tctl );
  231. E1000_WRITE_FLUSH ( hw );
  232. }
  233. /**
  234. * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
  235. *
  236. * @v adapter e1000 private structure
  237. *
  238. * @ret rc Returns 0 on success, negative on failure
  239. **/
  240. static int
  241. e1000_setup_rx_resources ( struct e1000_adapter *adapter )
  242. {
  243. int i, j;
  244. struct e1000_rx_desc *rx_curr_desc;
  245. DBG ( "e1000_setup_rx_resources\n" );
  246. /* Allocate receive descriptor ring memory.
  247. It must not cross a 64K boundary because of hardware errata
  248. */
  249. adapter->rx_base =
  250. malloc_dma ( adapter->rx_ring_size, adapter->rx_ring_size );
  251. if ( ! adapter->rx_base ) {
  252. return -ENOMEM;
  253. }
  254. memset ( adapter->rx_base, 0, adapter->rx_ring_size );
  255. for ( i = 0; i < NUM_RX_DESC; i++ ) {
  256. adapter->rx_iobuf[i] = alloc_iob ( MAXIMUM_ETHERNET_VLAN_SIZE );
  257. /* If unable to allocate all iobufs, free any that
  258. * were successfully allocated, and return an error
  259. */
  260. if ( ! adapter->rx_iobuf[i] ) {
  261. for ( j = 0; j < i; j++ ) {
  262. free_iob ( adapter->rx_iobuf[j] );
  263. }
  264. return -ENOMEM;
  265. }
  266. rx_curr_desc = ( void * ) ( adapter->rx_base ) +
  267. ( i * sizeof ( *adapter->rx_base ) );
  268. rx_curr_desc->buffer_addr = virt_to_bus ( adapter->rx_iobuf[i]->data );
  269. DBG ( "i = %d rx_curr_desc->buffer_addr = %#16llx\n",
  270. i, rx_curr_desc->buffer_addr );
  271. }
  272. return 0;
  273. }
  274. static void
  275. e1000_free_rx_resources ( struct e1000_adapter *adapter )
  276. {
  277. int i;
  278. DBG ( "e1000_free_rx_resources\n" );
  279. free_dma ( adapter->rx_base, adapter->rx_ring_size );
  280. for ( i = 0; i < NUM_RX_DESC; i++ ) {
  281. free_iob ( adapter->rx_iobuf[i] );
  282. }
  283. }
  284. /**
  285. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  286. * @adapter: board private structure
  287. *
  288. * Configure the Rx unit of the MAC after a reset.
  289. **/
  290. static void
  291. e1000_configure_rx ( struct e1000_adapter *adapter )
  292. {
  293. struct e1000_hw *hw = &adapter->hw;
  294. uint32_t rctl;
  295. DBG ( "e1000_configure_rx\n" );
  296. /* disable receives while setting up the descriptors */
  297. rctl = E1000_READ_REG ( hw, RCTL );
  298. E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
  299. adapter->rx_curr = 0;
  300. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  301. * the Base and Length of the Rx Descriptor Ring */
  302. E1000_WRITE_REG ( hw, RDBAL, virt_to_bus ( adapter->rx_base ) );
  303. E1000_WRITE_REG ( hw, RDBAH, 0 );
  304. E1000_WRITE_REG ( hw, RDLEN, adapter->rx_ring_size );
  305. E1000_WRITE_REG ( hw, RDH, 0 );
  306. E1000_WRITE_REG ( hw, RDT, NUM_RX_DESC - 1 );
  307. /* Enable Receives */
  308. rctl = ( E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
  309. E1000_RCTL_MPE
  310. );
  311. E1000_WRITE_REG ( hw, RCTL, rctl );
  312. E1000_WRITE_FLUSH ( hw );
  313. DBG ( "RDBAL: %#08x\n", E1000_READ_REG ( hw, RDBAL ) );
  314. DBG ( "RDLEN: %d\n", E1000_READ_REG ( hw, RDLEN ) );
  315. DBG ( "RCTL: %#08x\n", E1000_READ_REG ( hw, RCTL ) );
  316. }
  317. /**
  318. * e1000_reset - Put e1000 NIC in known initial state
  319. *
  320. * @v adapter e1000 private structure
  321. **/
  322. static void
  323. e1000_reset ( struct e1000_adapter *adapter )
  324. {
  325. uint32_t pba = 0;
  326. uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
  327. DBG ( "e1000_reset\n" );
  328. switch (adapter->hw.mac_type) {
  329. case e1000_82542_rev2_0:
  330. case e1000_82542_rev2_1:
  331. case e1000_82543:
  332. case e1000_82544:
  333. case e1000_82540:
  334. case e1000_82541:
  335. case e1000_82541_rev_2:
  336. pba = E1000_PBA_48K;
  337. break;
  338. case e1000_82545:
  339. case e1000_82545_rev_3:
  340. case e1000_82546:
  341. case e1000_82546_rev_3:
  342. pba = E1000_PBA_48K;
  343. break;
  344. case e1000_82547:
  345. case e1000_82547_rev_2:
  346. pba = E1000_PBA_30K;
  347. break;
  348. case e1000_82571:
  349. case e1000_82572:
  350. case e1000_80003es2lan:
  351. pba = E1000_PBA_38K;
  352. break;
  353. case e1000_82573:
  354. pba = E1000_PBA_20K;
  355. break;
  356. case e1000_ich8lan:
  357. pba = E1000_PBA_8K;
  358. case e1000_undefined:
  359. case e1000_num_macs:
  360. break;
  361. }
  362. E1000_WRITE_REG ( &adapter->hw, PBA, pba );
  363. /* flow control settings */
  364. /* Set the FC high water mark to 90% of the FIFO size.
  365. * Required to clear last 3 LSB */
  366. fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
  367. /* We can't use 90% on small FIFOs because the remainder
  368. * would be less than 1 full frame. In this case, we size
  369. * it to allow at least a full frame above the high water
  370. * mark. */
  371. if (pba < E1000_PBA_16K)
  372. fc_high_water_mark = (pba * 1024) - 1600;
  373. adapter->hw.fc_high_water = fc_high_water_mark;
  374. adapter->hw.fc_low_water = fc_high_water_mark - 8;
  375. if (adapter->hw.mac_type == e1000_80003es2lan)
  376. adapter->hw.fc_pause_time = 0xFFFF;
  377. else
  378. adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
  379. adapter->hw.fc_send_xon = 1;
  380. adapter->hw.fc = adapter->hw.original_fc;
  381. /* Allow time for pending master requests to run */
  382. e1000_reset_hw ( &adapter->hw );
  383. if ( adapter->hw.mac_type >= e1000_82544 )
  384. E1000_WRITE_REG ( &adapter->hw, WUC, 0 );
  385. if ( e1000_init_hw ( &adapter->hw ) )
  386. DBG ( "Hardware Error\n" );
  387. /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
  388. if (adapter->hw.mac_type >= e1000_82544 &&
  389. adapter->hw.mac_type <= e1000_82547_rev_2 &&
  390. adapter->hw.autoneg == 1 &&
  391. adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
  392. uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  393. /* clear phy power management bit if we are in gig only mode,
  394. * which if enabled will attempt negotiation to 100Mb, which
  395. * can cause a loss of link at power off or driver unload */
  396. ctrl &= ~E1000_CTRL_SWDPIN3;
  397. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  398. }
  399. e1000_phy_get_info ( &adapter->hw, &adapter->phy_info );
  400. if (!adapter->smart_power_down &&
  401. (adapter->hw.mac_type == e1000_82571 ||
  402. adapter->hw.mac_type == e1000_82572)) {
  403. uint16_t phy_data = 0;
  404. /* speed up time to link by disabling smart power down, ignore
  405. * the return value of this function because there is nothing
  406. * different we would do if it failed */
  407. e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
  408. &phy_data);
  409. phy_data &= ~IGP02E1000_PM_SPD;
  410. e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
  411. phy_data);
  412. }
  413. }
  414. /** Functions that implement the gPXE driver API **/
  415. /**
  416. * e1000_close - Disables a network interface
  417. *
  418. * @v netdev network interface device structure
  419. *
  420. **/
  421. static void
  422. e1000_close ( struct net_device *netdev )
  423. {
  424. struct e1000_adapter *adapter = netdev_priv ( netdev );
  425. struct e1000_hw *hw = &adapter->hw;
  426. uint32_t rctl;
  427. uint32_t icr;
  428. DBG ( "e1000_close\n" );
  429. /* Acknowledge interrupts */
  430. icr = E1000_READ_REG ( hw, ICR );
  431. e1000_irq_disable ( adapter );
  432. /* disable receives */
  433. rctl = E1000_READ_REG ( hw, RCTL );
  434. E1000_WRITE_REG ( hw, RCTL, rctl & ~E1000_RCTL_EN );
  435. E1000_WRITE_FLUSH ( hw );
  436. e1000_reset_hw ( hw );
  437. e1000_free_tx_resources ( adapter );
  438. e1000_free_rx_resources ( adapter );
  439. }
  440. /**
  441. * e1000_transmit - Transmit a packet
  442. *
  443. * @v netdev Network device
  444. * @v iobuf I/O buffer
  445. *
  446. * @ret rc Returns 0 on success, negative on failure
  447. */
  448. static int
  449. e1000_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
  450. {
  451. struct e1000_adapter *adapter = netdev_priv( netdev );
  452. struct e1000_hw *hw = &adapter->hw;
  453. uint32_t tx_curr = adapter->tx_tail;
  454. struct e1000_tx_desc *tx_curr_desc;
  455. DBG ("e1000_transmit\n");
  456. if ( adapter->tx_fill_ctr == NUM_TX_DESC ) {
  457. DBG ("TX overflow\n");
  458. return -ENOBUFS;
  459. }
  460. /* Save pointer to iobuf we have been given to transmit,
  461. netdev_tx_complete() will need it later
  462. */
  463. adapter->tx_iobuf[tx_curr] = iobuf;
  464. tx_curr_desc = ( void * ) ( adapter->tx_base ) +
  465. ( tx_curr * sizeof ( *adapter->tx_base ) );
  466. DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
  467. DBG ( "tx_curr_desc + 16 = %#08lx\n", virt_to_bus ( tx_curr_desc ) + 16 );
  468. DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
  469. /* Add the packet to TX ring
  470. */
  471. tx_curr_desc->buffer_addr =
  472. virt_to_bus ( iobuf->data );
  473. tx_curr_desc->lower.data =
  474. E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
  475. E1000_TXD_CMD_IFCS | iob_len ( iobuf );
  476. tx_curr_desc->upper.data = 0;
  477. DBG ( "TX fill: %d tx_curr: %d addr: %#08lx len: %zd\n", adapter->tx_fill_ctr,
  478. tx_curr, virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
  479. /* Point to next free descriptor */
  480. adapter->tx_tail = ( adapter->tx_tail + 1 ) % NUM_TX_DESC;
  481. adapter->tx_fill_ctr++;
  482. /* Write new tail to NIC, making packet available for transmit
  483. */
  484. wmb();
  485. E1000_WRITE_REG ( hw, TDT, adapter->tx_tail );
  486. return 0;
  487. }
  488. /**
  489. * e1000_poll - Poll for received packets
  490. *
  491. * @v netdev Network device
  492. */
  493. static void
  494. e1000_poll ( struct net_device *netdev )
  495. {
  496. struct e1000_adapter *adapter = netdev_priv( netdev );
  497. struct e1000_hw *hw = &adapter->hw;
  498. uint32_t icr;
  499. uint32_t tx_status;
  500. uint32_t rx_status;
  501. uint32_t rx_len;
  502. uint32_t rx_err;
  503. struct io_buffer *rx_iob;
  504. struct e1000_tx_desc *tx_curr_desc;
  505. struct e1000_rx_desc *rx_curr_desc;
  506. uint32_t i;
  507. uint64_t tmp_buffer_addr;
  508. DBGP ( "e1000_poll\n" );
  509. /* Acknowledge interrupts */
  510. icr = E1000_READ_REG ( hw, ICR );
  511. if ( ! icr )
  512. return;
  513. DBG ( "e1000_poll: intr_status = %#08x\n", icr );
  514. /* Check status of transmitted packets
  515. */
  516. while ( ( i = adapter->tx_head ) != adapter->tx_tail ) {
  517. tx_curr_desc = ( void * ) ( adapter->tx_base ) +
  518. ( i * sizeof ( *adapter->tx_base ) );
  519. tx_status = tx_curr_desc->upper.data;
  520. /* if the packet at tx_head is not owned by hardware it is for us */
  521. if ( ! ( tx_status & E1000_TXD_STAT_DD ) )
  522. break;
  523. DBG ( "Sent packet. tx_head: %d tx_tail: %d tx_status: %#08x\n",
  524. adapter->tx_head, adapter->tx_tail, tx_status );
  525. if ( tx_status & ( E1000_TXD_STAT_EC | E1000_TXD_STAT_LC |
  526. E1000_TXD_STAT_TU ) ) {
  527. netdev_tx_complete_err ( netdev, adapter->tx_iobuf[i], -EINVAL );
  528. DBG ( "Error transmitting packet, tx_status: %#08x\n",
  529. tx_status );
  530. } else {
  531. netdev_tx_complete ( netdev, adapter->tx_iobuf[i] );
  532. DBG ( "Success transmitting packet, tx_status: %#08x\n",
  533. tx_status );
  534. }
  535. /* Decrement count of used descriptors, clear this descriptor
  536. */
  537. adapter->tx_fill_ctr--;
  538. memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
  539. adapter->tx_head = ( adapter->tx_head + 1 ) % NUM_TX_DESC;
  540. }
  541. /* Process received packets
  542. */
  543. while ( 1 ) {
  544. i = adapter->rx_curr;
  545. rx_curr_desc = ( void * ) ( adapter->rx_base ) +
  546. ( i * sizeof ( *adapter->rx_base ) );
  547. rx_status = rx_curr_desc->status;
  548. DBG2 ( "Before DD Check RX_status: %#08x\n", rx_status );
  549. if ( ! ( rx_status & E1000_RXD_STAT_DD ) )
  550. break;
  551. DBG ( "RCTL = %#08x\n", E1000_READ_REG ( &adapter->hw, RCTL ) );
  552. rx_len = rx_curr_desc->length;
  553. DBG ( "Received packet, rx_curr: %d rx_status: %#08x rx_len: %d\n",
  554. i, rx_status, rx_len );
  555. rx_err = rx_curr_desc->errors;
  556. if ( rx_err & E1000_RXD_ERR_FRAME_ERR_MASK ) {
  557. netdev_rx_err ( netdev, NULL, -EINVAL );
  558. DBG ( "e1000_poll: Corrupted packet received!"
  559. " rx_err: %#08x\n", rx_err );
  560. } else {
  561. /* If unable allocate space for this packet,
  562. * try again next poll
  563. */
  564. rx_iob = alloc_iob ( rx_len );
  565. if ( ! rx_iob )
  566. break;
  567. memcpy ( iob_put ( rx_iob, rx_len ),
  568. adapter->rx_iobuf[i]->data, rx_len );
  569. /* Add this packet to the receive queue.
  570. */
  571. netdev_rx ( netdev, rx_iob );
  572. }
  573. tmp_buffer_addr = rx_curr_desc->buffer_addr;
  574. memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
  575. rx_curr_desc->buffer_addr = tmp_buffer_addr;
  576. E1000_WRITE_REG ( hw, RDT, adapter->rx_curr );
  577. adapter->rx_curr = ( adapter->rx_curr + 1 ) % NUM_RX_DESC;
  578. }
  579. }
  580. /**
  581. * e1000_irq - enable or Disable interrupts
  582. *
  583. * @v adapter e1000 adapter
  584. * @v action requested interrupt action
  585. **/
  586. static void
  587. e1000_irq ( struct net_device *netdev, int enable )
  588. {
  589. struct e1000_adapter *adapter = netdev_priv(netdev);
  590. DBG ( "e1000_irq\n" );
  591. switch ( enable ) {
  592. case 0 :
  593. e1000_irq_disable ( adapter );
  594. break;
  595. case 1 :
  596. e1000_irq_enable ( adapter );
  597. break;
  598. case 2 :
  599. e1000_irq_force ( adapter );
  600. break;
  601. }
  602. }
  603. static struct net_device_operations e1000_operations;
  604. /**
  605. * e1000_probe - Initial configuration of e1000 NIC
  606. *
  607. * @v pci PCI device
  608. * @v id PCI IDs
  609. *
  610. * @ret rc Return status code
  611. **/
  612. static int
  613. e1000_probe ( struct pci_device *pdev,
  614. const struct pci_device_id *id __unused )
  615. {
  616. int i, err;
  617. struct net_device *netdev;
  618. struct e1000_adapter *adapter;
  619. unsigned long mmio_start, mmio_len;
  620. unsigned long flash_start, flash_len;
  621. DBG ( "e1000_probe\n" );
  622. err = -ENOMEM;
  623. /* Allocate net device ( also allocates memory for netdev->priv
  624. and makes netdev-priv point to it ) */
  625. netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) );
  626. if ( ! netdev )
  627. goto err_alloc_etherdev;
  628. /* Associate e1000-specific network operations operations with
  629. * generic network device layer */
  630. netdev_init ( netdev, &e1000_operations );
  631. /* Associate this network device with given PCI device */
  632. pci_set_drvdata ( pdev, netdev );
  633. netdev->dev = &pdev->dev;
  634. /* Initialize driver private storage */
  635. adapter = netdev_priv ( netdev );
  636. memset ( adapter, 0, ( sizeof ( *adapter ) ) );
  637. adapter->hw.io_base = pdev->ioaddr;
  638. adapter->ioaddr = pdev->ioaddr;
  639. adapter->irqno = pdev->irq;
  640. adapter->netdev = netdev;
  641. adapter->pdev = pdev;
  642. adapter->hw.back = adapter;
  643. adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC;
  644. adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC;
  645. mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 );
  646. mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 );
  647. DBG ( "mmio_start: %#08lx\n", mmio_start );
  648. DBG ( "mmio_len: %#08lx\n", mmio_len );
  649. /* Fix up PCI device */
  650. adjust_pci_device ( pdev );
  651. err = -EIO;
  652. adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len );
  653. DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr );
  654. if ( ! adapter->hw.hw_addr )
  655. goto err_ioremap;
  656. /* setup the private structure */
  657. if ( ( err = e1000_sw_init ( adapter ) ) )
  658. goto err_sw_init;
  659. DBG ( "adapter->hw.mac_type: %#08x\n", adapter->hw.mac_type );
  660. /* Flash BAR mapping must happen after e1000_sw_init
  661. * because it depends on mac_type
  662. */
  663. if ( ( adapter->hw.mac_type == e1000_ich8lan ) && ( pdev->ioaddr ) ) {
  664. flash_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_1 );
  665. flash_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_1 );
  666. adapter->hw.flash_address = ioremap ( flash_start, flash_len );
  667. if ( ! adapter->hw.flash_address )
  668. goto err_flashmap;
  669. }
  670. /* initialize eeprom parameters */
  671. if ( e1000_init_eeprom_params ( &adapter->hw ) ) {
  672. DBG ( "EEPROM initialization failed\n" );
  673. goto err_eeprom;
  674. }
  675. /* before reading the EEPROM, reset the controller to
  676. * put the device in a known good starting state
  677. */
  678. err = e1000_reset_hw ( &adapter->hw );
  679. if ( err < 0 ) {
  680. DBG ( "Hardware Initialization Failed\n" );
  681. goto err_reset;
  682. }
  683. /* make sure the EEPROM is good */
  684. if ( e1000_validate_eeprom_checksum( &adapter->hw ) < 0 ) {
  685. DBG ( "The EEPROM Checksum Is Not Valid\n" );
  686. goto err_eeprom;
  687. }
  688. /* copy the MAC address out of the EEPROM */
  689. if ( e1000_read_mac_addr ( &adapter->hw ) )
  690. DBG ( "EEPROM Read Error\n" );
  691. memcpy ( netdev->hw_addr, adapter->hw.mac_addr, ETH_ALEN );
  692. /* print bus type/speed/width info */
  693. {
  694. struct e1000_hw *hw = &adapter->hw;
  695. DBG ( "(PCI%s:%s:%s) ",
  696. ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
  697. (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
  698. ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  699. (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
  700. (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
  701. (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
  702. (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
  703. ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
  704. (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
  705. (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
  706. "32-bit"));
  707. }
  708. for (i = 0; i < 6; i++)
  709. DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":");
  710. /* reset the hardware with the new settings */
  711. e1000_reset ( adapter );
  712. e1000_get_hw_control ( adapter );
  713. /* Mark as link up; we don't yet handle link state */
  714. netdev_link_up ( netdev );
  715. if ( ( err = register_netdev ( netdev ) ) != 0)
  716. goto err_register;
  717. DBG ( "e1000_probe succeeded!\n" );
  718. /* No errors, return success */
  719. return 0;
  720. /* Error return paths */
  721. err_reset:
  722. err_register:
  723. err_eeprom:
  724. if ( ! e1000_check_phy_reset_block ( &adapter->hw ) )
  725. e1000_phy_hw_reset ( &adapter->hw );
  726. if ( adapter->hw.flash_address )
  727. iounmap ( adapter->hw.flash_address );
  728. err_flashmap:
  729. err_sw_init:
  730. iounmap ( adapter->hw.hw_addr );
  731. err_ioremap:
  732. netdev_put ( netdev );
  733. err_alloc_etherdev:
  734. return err;
  735. }
  736. /**
  737. * e1000_remove - Device Removal Routine
  738. *
  739. * @v pdev PCI device information struct
  740. *
  741. **/
  742. static void
  743. e1000_remove ( struct pci_device *pdev )
  744. {
  745. struct net_device *netdev = pci_get_drvdata ( pdev );
  746. struct e1000_adapter *adapter = netdev_priv ( netdev );
  747. DBG ( "e1000_remove\n" );
  748. if ( adapter->hw.flash_address )
  749. iounmap ( adapter->hw.flash_address );
  750. if ( adapter->hw.hw_addr )
  751. iounmap ( adapter->hw.hw_addr );
  752. unregister_netdev ( netdev );
  753. e1000_reset_hw ( &adapter->hw );
  754. netdev_nullify ( netdev );
  755. netdev_put ( netdev );
  756. }
  757. /**
  758. * e1000_open - Called when a network interface is made active
  759. *
  760. * @v netdev network interface device structure
  761. * @ret rc Return status code, 0 on success, negative value on failure
  762. *
  763. **/
  764. static int
  765. e1000_open ( struct net_device *netdev )
  766. {
  767. struct e1000_adapter *adapter = netdev_priv(netdev);
  768. int err;
  769. DBG ( "e1000_open\n" );
  770. /* allocate transmit descriptors */
  771. err = e1000_setup_tx_resources ( adapter );
  772. if ( err ) {
  773. DBG ( "Error setting up TX resources!\n" );
  774. goto err_setup_tx;
  775. }
  776. /* allocate receive descriptors */
  777. err = e1000_setup_rx_resources ( adapter );
  778. if ( err ) {
  779. DBG ( "Error setting up RX resources!\n" );
  780. goto err_setup_rx;
  781. }
  782. e1000_configure_tx ( adapter );
  783. e1000_configure_rx ( adapter );
  784. DBG ( "RXDCTL: %#08x\n", E1000_READ_REG ( &adapter->hw, RXDCTL ) );
  785. return 0;
  786. err_setup_rx:
  787. e1000_free_tx_resources ( adapter );
  788. err_setup_tx:
  789. e1000_reset ( adapter );
  790. return err;
  791. }
  792. /** e1000 net device operations */
  793. static struct net_device_operations e1000_operations = {
  794. .open = e1000_open,
  795. .close = e1000_close,
  796. .transmit = e1000_transmit,
  797. .poll = e1000_poll,
  798. .irq = e1000_irq,
  799. };
  800. int32_t
  801. e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  802. {
  803. struct e1000_adapter *adapter = hw->back;
  804. uint16_t cap_offset;
  805. #define PCI_CAP_ID_EXP 0x10 /* PCI Express */
  806. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  807. if (!cap_offset)
  808. return -E1000_ERR_CONFIG;
  809. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  810. return 0;
  811. }
  812. void
  813. e1000_pci_clear_mwi ( struct e1000_hw *hw )
  814. {
  815. struct e1000_adapter *adapter = hw->back;
  816. pci_write_config_word ( adapter->pdev, PCI_COMMAND,
  817. hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE );
  818. }
  819. void
  820. e1000_pci_set_mwi ( struct e1000_hw *hw )
  821. {
  822. struct e1000_adapter *adapter = hw->back;
  823. pci_write_config_word ( adapter->pdev, PCI_COMMAND, hw->pci_cmd_word );
  824. }
  825. void
  826. e1000_read_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
  827. {
  828. struct e1000_adapter *adapter = hw->back;
  829. pci_read_config_word ( adapter->pdev, reg, value );
  830. }
  831. void
  832. e1000_write_pci_cfg ( struct e1000_hw *hw, uint32_t reg, uint16_t *value )
  833. {
  834. struct e1000_adapter *adapter = hw->back;
  835. pci_write_config_word ( adapter->pdev, reg, *value );
  836. }
  837. void
  838. e1000_io_write ( struct e1000_hw *hw __unused, unsigned long port, uint32_t value )
  839. {
  840. outl ( value, port );
  841. }
  842. static struct pci_device_id e1000_nics[] = {
  843. PCI_ROM(0x8086, 0x1000, "e1000-0x1000", "e1000-0x1000", 0),
  844. PCI_ROM(0x8086, 0x1001, "e1000-0x1001", "e1000-0x1001", 0),
  845. PCI_ROM(0x8086, 0x1004, "e1000-0x1004", "e1000-0x1004", 0),
  846. PCI_ROM(0x8086, 0x1008, "e1000-0x1008", "e1000-0x1008", 0),
  847. PCI_ROM(0x8086, 0x1009, "e1000-0x1009", "e1000-0x1009", 0),
  848. PCI_ROM(0x8086, 0x100c, "e1000-0x100c", "e1000-0x100c", 0),
  849. PCI_ROM(0x8086, 0x100d, "e1000-0x100d", "e1000-0x100d", 0),
  850. PCI_ROM(0x8086, 0x100e, "e1000-0x100e", "e1000-0x100e", 0),
  851. PCI_ROM(0x8086, 0x100f, "e1000-0x100f", "e1000-0x100f", 0),
  852. PCI_ROM(0x8086, 0x1010, "e1000-0x1010", "e1000-0x1010", 0),
  853. PCI_ROM(0x8086, 0x1011, "e1000-0x1011", "e1000-0x1011", 0),
  854. PCI_ROM(0x8086, 0x1012, "e1000-0x1012", "e1000-0x1012", 0),
  855. PCI_ROM(0x8086, 0x1013, "e1000-0x1013", "e1000-0x1013", 0),
  856. PCI_ROM(0x8086, 0x1014, "e1000-0x1014", "e1000-0x1014", 0),
  857. PCI_ROM(0x8086, 0x1015, "e1000-0x1015", "e1000-0x1015", 0),
  858. PCI_ROM(0x8086, 0x1016, "e1000-0x1016", "e1000-0x1016", 0),
  859. PCI_ROM(0x8086, 0x1017, "e1000-0x1017", "e1000-0x1017", 0),
  860. PCI_ROM(0x8086, 0x1018, "e1000-0x1018", "e1000-0x1018", 0),
  861. PCI_ROM(0x8086, 0x1019, "e1000-0x1019", "e1000-0x1019", 0),
  862. PCI_ROM(0x8086, 0x101a, "e1000-0x101a", "e1000-0x101a", 0),
  863. PCI_ROM(0x8086, 0x101d, "e1000-0x101d", "e1000-0x101d", 0),
  864. PCI_ROM(0x8086, 0x101e, "e1000-0x101e", "e1000-0x101e", 0),
  865. PCI_ROM(0x8086, 0x1026, "e1000-0x1026", "e1000-0x1026", 0),
  866. PCI_ROM(0x8086, 0x1027, "e1000-0x1027", "e1000-0x1027", 0),
  867. PCI_ROM(0x8086, 0x1028, "e1000-0x1028", "e1000-0x1028", 0),
  868. PCI_ROM(0x8086, 0x1049, "e1000-0x1049", "e1000-0x1049", 0),
  869. PCI_ROM(0x8086, 0x104a, "e1000-0x104a", "e1000-0x104a", 0),
  870. PCI_ROM(0x8086, 0x104b, "e1000-0x104b", "e1000-0x104b", 0),
  871. PCI_ROM(0x8086, 0x104c, "e1000-0x104c", "e1000-0x104c", 0),
  872. PCI_ROM(0x8086, 0x104d, "e1000-0x104d", "e1000-0x104d", 0),
  873. PCI_ROM(0x8086, 0x105e, "e1000-0x105e", "e1000-0x105e", 0),
  874. PCI_ROM(0x8086, 0x105f, "e1000-0x105f", "e1000-0x105f", 0),
  875. PCI_ROM(0x8086, 0x1060, "e1000-0x1060", "e1000-0x1060", 0),
  876. PCI_ROM(0x8086, 0x1075, "e1000-0x1075", "e1000-0x1075", 0),
  877. PCI_ROM(0x8086, 0x1076, "e1000-0x1076", "e1000-0x1076", 0),
  878. PCI_ROM(0x8086, 0x1077, "e1000-0x1077", "e1000-0x1077", 0),
  879. PCI_ROM(0x8086, 0x1078, "e1000-0x1078", "e1000-0x1078", 0),
  880. PCI_ROM(0x8086, 0x1079, "e1000-0x1079", "e1000-0x1079", 0),
  881. PCI_ROM(0x8086, 0x107a, "e1000-0x107a", "e1000-0x107a", 0),
  882. PCI_ROM(0x8086, 0x107b, "e1000-0x107b", "e1000-0x107b", 0),
  883. PCI_ROM(0x8086, 0x107c, "e1000-0x107c", "e1000-0x107c", 0),
  884. PCI_ROM(0x8086, 0x107d, "e1000-0x107d", "e1000-0x107d", 0),
  885. PCI_ROM(0x8086, 0x107e, "e1000-0x107e", "e1000-0x107e", 0),
  886. PCI_ROM(0x8086, 0x107f, "e1000-0x107f", "e1000-0x107f", 0),
  887. PCI_ROM(0x8086, 0x108a, "e1000-0x108a", "e1000-0x108a", 0),
  888. PCI_ROM(0x8086, 0x108b, "e1000-0x108b", "e1000-0x108b", 0),
  889. PCI_ROM(0x8086, 0x108c, "e1000-0x108c", "e1000-0x108c", 0),
  890. PCI_ROM(0x8086, 0x1096, "e1000-0x1096", "e1000-0x1096", 0),
  891. PCI_ROM(0x8086, 0x1098, "e1000-0x1098", "e1000-0x1098", 0),
  892. PCI_ROM(0x8086, 0x1099, "e1000-0x1099", "e1000-0x1099", 0),
  893. PCI_ROM(0x8086, 0x109a, "e1000-0x109a", "e1000-0x109a", 0),
  894. PCI_ROM(0x8086, 0x10a4, "e1000-0x10a4", "e1000-0x10a4", 0),
  895. PCI_ROM(0x8086, 0x10a5, "e1000-0x10a5", "e1000-0x10a5", 0),
  896. PCI_ROM(0x8086, 0x10b5, "e1000-0x10b5", "e1000-0x10b5", 0),
  897. PCI_ROM(0x8086, 0x10b9, "e1000-0x10b9", "e1000-0x10b9", 0),
  898. PCI_ROM(0x8086, 0x10ba, "e1000-0x10ba", "e1000-0x10ba", 0),
  899. PCI_ROM(0x8086, 0x10bb, "e1000-0x10bb", "e1000-0x10bb", 0),
  900. PCI_ROM(0x8086, 0x10bc, "e1000-0x10bc", "e1000-0x10bc", 0),
  901. PCI_ROM(0x8086, 0x10c4, "e1000-0x10c4", "e1000-0x10c4", 0),
  902. PCI_ROM(0x8086, 0x10c5, "e1000-0x10c5", "e1000-0x10c5", 0),
  903. PCI_ROM(0x8086, 0x10d9, "e1000-0x10d9", "e1000-0x10d9", 0),
  904. PCI_ROM(0x8086, 0x10da, "e1000-0x10da", "e1000-0x10da", 0),
  905. };
  906. struct pci_driver e1000_driver __pci_driver = {
  907. .ids = e1000_nics,
  908. .id_count = (sizeof (e1000_nics) / sizeof (e1000_nics[0])),
  909. .probe = e1000_probe,
  910. .remove = e1000_remove,
  911. };
  912. /*
  913. * Local variables:
  914. * c-basic-offset: 8
  915. * c-indent-level: 8
  916. * tab-width: 8
  917. * End:
  918. */