You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

intelxl.c 47KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  1. /*
  2. * Copyright (C) 2018 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <unistd.h>
  28. #include <errno.h>
  29. #include <byteswap.h>
  30. #include <ipxe/netdevice.h>
  31. #include <ipxe/ethernet.h>
  32. #include <ipxe/if_ether.h>
  33. #include <ipxe/vlan.h>
  34. #include <ipxe/iobuf.h>
  35. #include <ipxe/malloc.h>
  36. #include <ipxe/pci.h>
  37. #include <ipxe/version.h>
  38. #include "intelxl.h"
  39. /** @file
  40. *
  41. * Intel 40 Gigabit Ethernet network card driver
  42. *
  43. */
  44. /******************************************************************************
  45. *
  46. * Device reset
  47. *
  48. ******************************************************************************
  49. */
  50. /**
  51. * Reset hardware
  52. *
  53. * @v intelxl Intel device
  54. * @ret rc Return status code
  55. */
  56. static int intelxl_reset ( struct intelxl_nic *intelxl ) {
  57. uint32_t pfgen_ctrl;
  58. /* Perform a global software reset */
  59. pfgen_ctrl = readl ( intelxl->regs + INTELXL_PFGEN_CTRL );
  60. writel ( ( pfgen_ctrl | INTELXL_PFGEN_CTRL_PFSWR ),
  61. intelxl->regs + INTELXL_PFGEN_CTRL );
  62. mdelay ( INTELXL_RESET_DELAY_MS );
  63. return 0;
  64. }
  65. /******************************************************************************
  66. *
  67. * MAC address
  68. *
  69. ******************************************************************************
  70. */
  71. /**
  72. * Fetch initial MAC address and maximum frame size
  73. *
  74. * @v intelxl Intel device
  75. * @v netdev Network device
  76. * @ret rc Return status code
  77. */
  78. static int intelxl_fetch_mac ( struct intelxl_nic *intelxl,
  79. struct net_device *netdev ) {
  80. union intelxl_receive_address mac;
  81. uint32_t prtgl_sal;
  82. uint32_t prtgl_sah;
  83. size_t mfs;
  84. /* Read NVM-loaded address */
  85. prtgl_sal = readl ( intelxl->regs + INTELXL_PRTGL_SAL );
  86. prtgl_sah = readl ( intelxl->regs + INTELXL_PRTGL_SAH );
  87. mac.reg.low = cpu_to_le32 ( prtgl_sal );
  88. mac.reg.high = cpu_to_le32 ( prtgl_sah );
  89. /* Check that address is valid */
  90. if ( ! is_valid_ether_addr ( mac.raw ) ) {
  91. DBGC ( intelxl, "INTELXL %p has invalid MAC address (%s)\n",
  92. intelxl, eth_ntoa ( mac.raw ) );
  93. return -ENOENT;
  94. }
  95. /* Copy MAC address */
  96. DBGC ( intelxl, "INTELXL %p has autoloaded MAC address %s\n",
  97. intelxl, eth_ntoa ( mac.raw ) );
  98. memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
  99. /* Get maximum frame size */
  100. mfs = INTELXL_PRTGL_SAH_MFS_GET ( prtgl_sah );
  101. netdev->max_pkt_len = ( mfs - 4 /* CRC */ );
  102. return 0;
  103. }
  104. /******************************************************************************
  105. *
  106. * Admin queue
  107. *
  108. ******************************************************************************
  109. */
  110. /** Admin queue register offsets */
  111. static const struct intelxl_admin_offsets intelxl_admin_offsets = {
  112. .bal = INTELXL_ADMIN_BAL,
  113. .bah = INTELXL_ADMIN_BAH,
  114. .len = INTELXL_ADMIN_LEN,
  115. .head = INTELXL_ADMIN_HEAD,
  116. .tail = INTELXL_ADMIN_TAIL,
  117. };
  118. /**
  119. * Allocate admin queue
  120. *
  121. * @v intelxl Intel device
  122. * @v admin Admin queue
  123. * @ret rc Return status code
  124. */
  125. static int intelxl_alloc_admin ( struct intelxl_nic *intelxl,
  126. struct intelxl_admin *admin ) {
  127. size_t buf_len = ( sizeof ( admin->buf[0] ) * INTELXL_ADMIN_NUM_DESC );
  128. size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
  129. /* Allocate admin queue */
  130. admin->buf = malloc_dma ( ( buf_len + len ), INTELXL_ALIGN );
  131. if ( ! admin->buf )
  132. return -ENOMEM;
  133. admin->desc = ( ( ( void * ) admin->buf ) + buf_len );
  134. DBGC ( intelxl, "INTELXL %p A%cQ is at [%08llx,%08llx) buf "
  135. "[%08llx,%08llx)\n", intelxl,
  136. ( ( admin == &intelxl->command ) ? 'T' : 'R' ),
  137. ( ( unsigned long long ) virt_to_bus ( admin->desc ) ),
  138. ( ( unsigned long long ) ( virt_to_bus ( admin->desc ) + len ) ),
  139. ( ( unsigned long long ) virt_to_bus ( admin->buf ) ),
  140. ( ( unsigned long long ) ( virt_to_bus ( admin->buf ) +
  141. buf_len ) ) );
  142. return 0;
  143. }
  144. /**
  145. * Enable admin queue
  146. *
  147. * @v intelxl Intel device
  148. * @v admin Admin queue
  149. */
  150. static void intelxl_enable_admin ( struct intelxl_nic *intelxl,
  151. struct intelxl_admin *admin ) {
  152. size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
  153. const struct intelxl_admin_offsets *regs = admin->regs;
  154. void *admin_regs = ( intelxl->regs + admin->base );
  155. physaddr_t address;
  156. /* Initialise admin queue */
  157. memset ( admin->desc, 0, len );
  158. /* Reset head and tail registers */
  159. writel ( 0, admin_regs + regs->head );
  160. writel ( 0, admin_regs + regs->tail );
  161. /* Reset queue index */
  162. admin->index = 0;
  163. /* Program queue address */
  164. address = virt_to_bus ( admin->desc );
  165. writel ( ( address & 0xffffffffUL ), admin_regs + regs->bal );
  166. if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
  167. writel ( ( ( ( uint64_t ) address ) >> 32 ),
  168. admin_regs + regs->bah );
  169. } else {
  170. writel ( 0, admin_regs + regs->bah );
  171. }
  172. /* Program queue length and enable queue */
  173. writel ( ( INTELXL_ADMIN_LEN_LEN ( INTELXL_ADMIN_NUM_DESC ) |
  174. INTELXL_ADMIN_LEN_ENABLE ),
  175. admin_regs + regs->len );
  176. }
  177. /**
  178. * Disable admin queue
  179. *
  180. * @v intelxl Intel device
  181. * @v admin Admin queue
  182. */
  183. static void intelxl_disable_admin ( struct intelxl_nic *intelxl,
  184. struct intelxl_admin *admin ) {
  185. const struct intelxl_admin_offsets *regs = admin->regs;
  186. void *admin_regs = ( intelxl->regs + admin->base );
  187. /* Disable queue */
  188. writel ( 0, admin_regs + regs->len );
  189. }
  190. /**
  191. * Free admin queue
  192. *
  193. * @v intelxl Intel device
  194. * @v admin Admin queue
  195. */
  196. static void intelxl_free_admin ( struct intelxl_nic *intelxl __unused,
  197. struct intelxl_admin *admin ) {
  198. size_t buf_len = ( sizeof ( admin->buf[0] ) * INTELXL_ADMIN_NUM_DESC );
  199. size_t len = ( sizeof ( admin->desc[0] ) * INTELXL_ADMIN_NUM_DESC );
  200. /* Free queue */
  201. free_dma ( admin->buf, ( buf_len + len ) );
  202. }
  203. /**
  204. * Get next admin command queue descriptor
  205. *
  206. * @v intelxl Intel device
  207. * @ret cmd Command descriptor
  208. */
  209. struct intelxl_admin_descriptor *
  210. intelxl_admin_command_descriptor ( struct intelxl_nic *intelxl ) {
  211. struct intelxl_admin *admin = &intelxl->command;
  212. struct intelxl_admin_descriptor *cmd;
  213. /* Get and initialise next descriptor */
  214. cmd = &admin->desc[ admin->index % INTELXL_ADMIN_NUM_DESC ];
  215. memset ( cmd, 0, sizeof ( *cmd ) );
  216. return cmd;
  217. }
  218. /**
  219. * Get next admin command queue data buffer
  220. *
  221. * @v intelxl Intel device
  222. * @ret buf Data buffer
  223. */
  224. union intelxl_admin_buffer *
  225. intelxl_admin_command_buffer ( struct intelxl_nic *intelxl ) {
  226. struct intelxl_admin *admin = &intelxl->command;
  227. union intelxl_admin_buffer *buf;
  228. /* Get next data buffer */
  229. buf = &admin->buf[ admin->index % INTELXL_ADMIN_NUM_DESC ];
  230. memset ( buf, 0, sizeof ( *buf ) );
  231. return buf;
  232. }
  233. /**
  234. * Initialise admin event queue descriptor
  235. *
  236. * @v intelxl Intel device
  237. * @v index Event queue index
  238. */
  239. static void intelxl_admin_event_init ( struct intelxl_nic *intelxl,
  240. unsigned int index ) {
  241. struct intelxl_admin *admin = &intelxl->event;
  242. struct intelxl_admin_descriptor *evt;
  243. union intelxl_admin_buffer *buf;
  244. uint64_t address;
  245. /* Initialise descriptor */
  246. evt = &admin->desc[ index % INTELXL_ADMIN_NUM_DESC ];
  247. buf = &admin->buf[ index % INTELXL_ADMIN_NUM_DESC ];
  248. address = virt_to_bus ( buf );
  249. evt->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_BUF );
  250. evt->len = cpu_to_le16 ( sizeof ( *buf ) );
  251. evt->params.buffer.high = cpu_to_le32 ( address >> 32 );
  252. evt->params.buffer.low = cpu_to_le32 ( address & 0xffffffffUL );
  253. }
  254. /**
  255. * Issue admin queue command
  256. *
  257. * @v intelxl Intel device
  258. * @ret rc Return status code
  259. */
  260. int intelxl_admin_command ( struct intelxl_nic *intelxl ) {
  261. struct intelxl_admin *admin = &intelxl->command;
  262. const struct intelxl_admin_offsets *regs = admin->regs;
  263. void *admin_regs = ( intelxl->regs + admin->base );
  264. struct intelxl_admin_descriptor *cmd;
  265. union intelxl_admin_buffer *buf;
  266. uint64_t address;
  267. uint32_t cookie;
  268. unsigned int index;
  269. unsigned int tail;
  270. unsigned int i;
  271. int rc;
  272. /* Get next queue entry */
  273. index = admin->index++;
  274. tail = ( admin->index % INTELXL_ADMIN_NUM_DESC );
  275. cmd = &admin->desc[ index % INTELXL_ADMIN_NUM_DESC ];
  276. buf = &admin->buf[ index % INTELXL_ADMIN_NUM_DESC ];
  277. DBGC2 ( intelxl, "INTELXL %p admin command %#x opcode %#04x",
  278. intelxl, index, le16_to_cpu ( cmd->opcode ) );
  279. if ( cmd->vopcode )
  280. DBGC2 ( intelxl, "/%#08x", le32_to_cpu ( cmd->vopcode ) );
  281. DBGC2 ( intelxl, ":\n" );
  282. /* Sanity checks */
  283. assert ( ! ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_DD ) ) );
  284. assert ( ! ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_CMP ) ) );
  285. assert ( ! ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_ERR ) ) );
  286. assert ( cmd->ret == 0 );
  287. /* Populate data buffer address if applicable */
  288. if ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_BUF ) ) {
  289. address = virt_to_bus ( buf );
  290. cmd->params.buffer.high = cpu_to_le32 ( address >> 32 );
  291. cmd->params.buffer.low = cpu_to_le32 ( address & 0xffffffffUL );
  292. }
  293. /* Populate cookie, if not being (ab)used for VF opcode */
  294. if ( ! cmd->vopcode )
  295. cmd->cookie = cpu_to_le32 ( index );
  296. /* Record cookie */
  297. cookie = cmd->cookie;
  298. /* Post command descriptor */
  299. DBGC2_HDA ( intelxl, virt_to_phys ( cmd ), cmd, sizeof ( *cmd ) );
  300. if ( cmd->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_BUF ) ) {
  301. DBGC2_HDA ( intelxl, virt_to_phys ( buf ), buf,
  302. le16_to_cpu ( cmd->len ) );
  303. }
  304. wmb();
  305. writel ( tail, admin_regs + regs->tail );
  306. /* Wait for completion */
  307. for ( i = 0 ; i < INTELXL_ADMIN_MAX_WAIT_MS ; i++ ) {
  308. /* If response is not complete, delay 1ms and retry */
  309. if ( ! ( cmd->flags & INTELXL_ADMIN_FL_DD ) ) {
  310. mdelay ( 1 );
  311. continue;
  312. }
  313. DBGC2 ( intelxl, "INTELXL %p admin command %#x response:\n",
  314. intelxl, index );
  315. DBGC2_HDA ( intelxl, virt_to_phys ( cmd ), cmd,
  316. sizeof ( *cmd ) );
  317. /* Check for cookie mismatch */
  318. if ( cmd->cookie != cookie ) {
  319. DBGC ( intelxl, "INTELXL %p admin command %#x bad "
  320. "cookie %#x\n", intelxl, index,
  321. le32_to_cpu ( cmd->cookie ) );
  322. rc = -EPROTO;
  323. goto err;
  324. }
  325. /* Check for errors */
  326. if ( cmd->ret != 0 ) {
  327. DBGC ( intelxl, "INTELXL %p admin command %#x error "
  328. "%d\n", intelxl, index,
  329. le16_to_cpu ( cmd->ret ) );
  330. rc = -EIO;
  331. goto err;
  332. }
  333. /* Success */
  334. return 0;
  335. }
  336. rc = -ETIMEDOUT;
  337. DBGC ( intelxl, "INTELXL %p timed out waiting for admin command %#x:\n",
  338. intelxl, index );
  339. err:
  340. DBGC_HDA ( intelxl, virt_to_phys ( cmd ), cmd, sizeof ( *cmd ) );
  341. return rc;
  342. }
  343. /**
  344. * Get firmware version
  345. *
  346. * @v intelxl Intel device
  347. * @ret rc Return status code
  348. */
  349. static int intelxl_admin_version ( struct intelxl_nic *intelxl ) {
  350. struct intelxl_admin_descriptor *cmd;
  351. struct intelxl_admin_version_params *version;
  352. unsigned int api;
  353. int rc;
  354. /* Populate descriptor */
  355. cmd = intelxl_admin_command_descriptor ( intelxl );
  356. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_VERSION );
  357. version = &cmd->params.version;
  358. /* Issue command */
  359. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  360. return rc;
  361. api = le16_to_cpu ( version->api.major );
  362. DBGC ( intelxl, "INTELXL %p firmware v%d.%d API v%d.%d\n",
  363. intelxl, le16_to_cpu ( version->firmware.major ),
  364. le16_to_cpu ( version->firmware.minor ),
  365. api, le16_to_cpu ( version->api.minor ) );
  366. /* Check for API compatibility */
  367. if ( api > INTELXL_ADMIN_API_MAJOR ) {
  368. DBGC ( intelxl, "INTELXL %p unsupported API v%d\n",
  369. intelxl, api );
  370. return -ENOTSUP;
  371. }
  372. return 0;
  373. }
  374. /**
  375. * Report driver version
  376. *
  377. * @v intelxl Intel device
  378. * @ret rc Return status code
  379. */
  380. static int intelxl_admin_driver ( struct intelxl_nic *intelxl ) {
  381. struct intelxl_admin_descriptor *cmd;
  382. struct intelxl_admin_driver_params *driver;
  383. union intelxl_admin_buffer *buf;
  384. int rc;
  385. /* Populate descriptor */
  386. cmd = intelxl_admin_command_descriptor ( intelxl );
  387. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_DRIVER );
  388. cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_RD | INTELXL_ADMIN_FL_BUF );
  389. cmd->len = cpu_to_le16 ( sizeof ( buf->driver ) );
  390. driver = &cmd->params.driver;
  391. driver->major = product_major_version;
  392. driver->minor = product_minor_version;
  393. buf = intelxl_admin_command_buffer ( intelxl );
  394. snprintf ( buf->driver.name, sizeof ( buf->driver.name ), "%s",
  395. ( product_name[0] ? product_name : product_short_name ) );
  396. /* Issue command */
  397. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  398. return rc;
  399. return 0;
  400. }
  401. /**
  402. * Shutdown admin queues
  403. *
  404. * @v intelxl Intel device
  405. * @ret rc Return status code
  406. */
  407. static int intelxl_admin_shutdown ( struct intelxl_nic *intelxl ) {
  408. struct intelxl_admin_descriptor *cmd;
  409. struct intelxl_admin_shutdown_params *shutdown;
  410. int rc;
  411. /* Populate descriptor */
  412. cmd = intelxl_admin_command_descriptor ( intelxl );
  413. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_SHUTDOWN );
  414. shutdown = &cmd->params.shutdown;
  415. shutdown->unloading = INTELXL_ADMIN_SHUTDOWN_UNLOADING;
  416. /* Issue command */
  417. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  418. return rc;
  419. return 0;
  420. }
  421. /**
  422. * Get switch configuration
  423. *
  424. * @v intelxl Intel device
  425. * @ret rc Return status code
  426. */
  427. static int intelxl_admin_switch ( struct intelxl_nic *intelxl ) {
  428. struct intelxl_admin_descriptor *cmd;
  429. struct intelxl_admin_switch_params *sw;
  430. union intelxl_admin_buffer *buf;
  431. int rc;
  432. /* Populate descriptor */
  433. cmd = intelxl_admin_command_descriptor ( intelxl );
  434. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_SWITCH );
  435. cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_BUF );
  436. cmd->len = cpu_to_le16 ( sizeof ( buf->sw ) );
  437. sw = &cmd->params.sw;
  438. buf = intelxl_admin_command_buffer ( intelxl );
  439. /* Get each configuration in turn */
  440. do {
  441. /* Issue command */
  442. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  443. return rc;
  444. /* Dump raw configuration */
  445. DBGC2 ( intelxl, "INTELXL %p SEID %#04x:\n",
  446. intelxl, le16_to_cpu ( buf->sw.cfg.seid ) );
  447. DBGC2_HDA ( intelxl, 0, &buf->sw.cfg, sizeof ( buf->sw.cfg ) );
  448. /* Parse response */
  449. if ( buf->sw.cfg.type == INTELXL_ADMIN_SWITCH_TYPE_VSI ) {
  450. intelxl->vsi = le16_to_cpu ( buf->sw.cfg.seid );
  451. DBGC ( intelxl, "INTELXL %p VSI %#04x uplink %#04x "
  452. "downlink %#04x conn %#02x\n", intelxl,
  453. intelxl->vsi, le16_to_cpu ( buf->sw.cfg.uplink ),
  454. le16_to_cpu ( buf->sw.cfg.downlink ),
  455. buf->sw.cfg.connection );
  456. }
  457. } while ( sw->next );
  458. /* Check that we found a VSI */
  459. if ( ! intelxl->vsi ) {
  460. DBGC ( intelxl, "INTELXL %p has no VSI\n", intelxl );
  461. return -ENOENT;
  462. }
  463. return 0;
  464. }
  465. /**
  466. * Get VSI parameters
  467. *
  468. * @v intelxl Intel device
  469. * @ret rc Return status code
  470. */
  471. static int intelxl_admin_vsi ( struct intelxl_nic *intelxl ) {
  472. struct intelxl_admin_descriptor *cmd;
  473. struct intelxl_admin_vsi_params *vsi;
  474. union intelxl_admin_buffer *buf;
  475. int rc;
  476. /* Populate descriptor */
  477. cmd = intelxl_admin_command_descriptor ( intelxl );
  478. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_VSI );
  479. cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_BUF );
  480. cmd->len = cpu_to_le16 ( sizeof ( buf->vsi ) );
  481. vsi = &cmd->params.vsi;
  482. vsi->vsi = cpu_to_le16 ( intelxl->vsi );
  483. buf = intelxl_admin_command_buffer ( intelxl );
  484. /* Issue command */
  485. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  486. return rc;
  487. /* Parse response */
  488. intelxl->queue = le16_to_cpu ( buf->vsi.queue[0] );
  489. intelxl->qset = le16_to_cpu ( buf->vsi.qset[0] );
  490. DBGC ( intelxl, "INTELXL %p VSI %#04x queue %#04x qset %#04x\n",
  491. intelxl, intelxl->vsi, intelxl->queue, intelxl->qset );
  492. return 0;
  493. }
  494. /**
  495. * Set VSI promiscuous modes
  496. *
  497. * @v intelxl Intel device
  498. * @ret rc Return status code
  499. */
  500. static int intelxl_admin_promisc ( struct intelxl_nic *intelxl ) {
  501. struct intelxl_admin_descriptor *cmd;
  502. struct intelxl_admin_promisc_params *promisc;
  503. uint16_t flags;
  504. int rc;
  505. /* Populate descriptor */
  506. cmd = intelxl_admin_command_descriptor ( intelxl );
  507. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_PROMISC );
  508. flags = ( INTELXL_ADMIN_PROMISC_FL_UNICAST |
  509. INTELXL_ADMIN_PROMISC_FL_MULTICAST |
  510. INTELXL_ADMIN_PROMISC_FL_BROADCAST |
  511. INTELXL_ADMIN_PROMISC_FL_VLAN );
  512. promisc = &cmd->params.promisc;
  513. promisc->flags = cpu_to_le16 ( flags );
  514. promisc->valid = cpu_to_le16 ( flags );
  515. promisc->vsi = cpu_to_le16 ( intelxl->vsi );
  516. /* Issue command */
  517. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  518. return rc;
  519. return 0;
  520. }
  521. /**
  522. * Restart autonegotiation
  523. *
  524. * @v intelxl Intel device
  525. * @ret rc Return status code
  526. */
  527. static int intelxl_admin_autoneg ( struct intelxl_nic *intelxl ) {
  528. struct intelxl_admin_descriptor *cmd;
  529. struct intelxl_admin_autoneg_params *autoneg;
  530. int rc;
  531. /* Populate descriptor */
  532. cmd = intelxl_admin_command_descriptor ( intelxl );
  533. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_AUTONEG );
  534. autoneg = &cmd->params.autoneg;
  535. autoneg->flags = ( INTELXL_ADMIN_AUTONEG_FL_RESTART |
  536. INTELXL_ADMIN_AUTONEG_FL_ENABLE );
  537. /* Issue command */
  538. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  539. return rc;
  540. return 0;
  541. }
  542. /**
  543. * Get link status
  544. *
  545. * @v netdev Network device
  546. * @ret rc Return status code
  547. */
  548. static int intelxl_admin_link ( struct net_device *netdev ) {
  549. struct intelxl_nic *intelxl = netdev->priv;
  550. struct intelxl_admin_descriptor *cmd;
  551. struct intelxl_admin_link_params *link;
  552. int rc;
  553. /* Populate descriptor */
  554. cmd = intelxl_admin_command_descriptor ( intelxl );
  555. cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_LINK );
  556. link = &cmd->params.link;
  557. link->notify = INTELXL_ADMIN_LINK_NOTIFY;
  558. /* Issue command */
  559. if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
  560. return rc;
  561. DBGC ( intelxl, "INTELXL %p PHY %#02x speed %#02x status %#02x\n",
  562. intelxl, link->phy, link->speed, link->status );
  563. /* Update network device */
  564. if ( link->status & INTELXL_ADMIN_LINK_UP ) {
  565. netdev_link_up ( netdev );
  566. } else {
  567. netdev_link_down ( netdev );
  568. }
  569. return 0;
  570. }
  571. /**
  572. * Handle virtual function event (when VF driver is not present)
  573. *
  574. * @v netdev Network device
  575. * @v evt Admin queue event descriptor
  576. * @v buf Admin queue event data buffer
  577. */
  578. __weak void
  579. intelxlvf_admin_event ( struct net_device *netdev __unused,
  580. struct intelxl_admin_descriptor *evt __unused,
  581. union intelxl_admin_buffer *buf __unused ) {
  582. /* Nothing to do */
  583. }
  584. /**
  585. * Refill admin event queue
  586. *
  587. * @v intelxl Intel device
  588. */
  589. static void intelxl_refill_admin ( struct intelxl_nic *intelxl ) {
  590. struct intelxl_admin *admin = &intelxl->event;
  591. const struct intelxl_admin_offsets *regs = admin->regs;
  592. void *admin_regs = ( intelxl->regs + admin->base );
  593. unsigned int tail;
  594. /* Update tail pointer */
  595. tail = ( ( admin->index + INTELXL_ADMIN_NUM_DESC - 1 ) %
  596. INTELXL_ADMIN_NUM_DESC );
  597. wmb();
  598. writel ( tail, admin_regs + regs->tail );
  599. }
  600. /**
  601. * Poll admin event queue
  602. *
  603. * @v netdev Network device
  604. */
  605. void intelxl_poll_admin ( struct net_device *netdev ) {
  606. struct intelxl_nic *intelxl = netdev->priv;
  607. struct intelxl_admin *admin = &intelxl->event;
  608. struct intelxl_admin_descriptor *evt;
  609. union intelxl_admin_buffer *buf;
  610. /* Check for events */
  611. while ( 1 ) {
  612. /* Get next event descriptor and data buffer */
  613. evt = &admin->desc[ admin->index % INTELXL_ADMIN_NUM_DESC ];
  614. buf = &admin->buf[ admin->index % INTELXL_ADMIN_NUM_DESC ];
  615. /* Stop if descriptor is not yet completed */
  616. if ( ! ( evt->flags & INTELXL_ADMIN_FL_DD ) )
  617. return;
  618. DBGC2 ( intelxl, "INTELXL %p admin event %#x:\n",
  619. intelxl, admin->index );
  620. DBGC2_HDA ( intelxl, virt_to_phys ( evt ), evt,
  621. sizeof ( *evt ) );
  622. if ( evt->flags & cpu_to_le16 ( INTELXL_ADMIN_FL_BUF ) ) {
  623. DBGC2_HDA ( intelxl, virt_to_phys ( buf ), buf,
  624. le16_to_cpu ( evt->len ) );
  625. }
  626. /* Handle event */
  627. switch ( evt->opcode ) {
  628. case cpu_to_le16 ( INTELXL_ADMIN_LINK ):
  629. intelxl_admin_link ( netdev );
  630. break;
  631. case cpu_to_le16 ( INTELXL_ADMIN_SEND_TO_VF ):
  632. intelxlvf_admin_event ( netdev, evt, buf );
  633. break;
  634. default:
  635. DBGC ( intelxl, "INTELXL %p admin event %#x "
  636. "unrecognised opcode %#04x\n", intelxl,
  637. admin->index, le16_to_cpu ( evt->opcode ) );
  638. break;
  639. }
  640. /* Reset descriptor and refill queue */
  641. intelxl_admin_event_init ( intelxl, admin->index );
  642. admin->index++;
  643. intelxl_refill_admin ( intelxl );
  644. }
  645. }
  646. /**
  647. * Open admin queues
  648. *
  649. * @v intelxl Intel device
  650. * @ret rc Return status code
  651. */
  652. int intelxl_open_admin ( struct intelxl_nic *intelxl ) {
  653. int rc;
  654. /* Allocate admin event queue */
  655. if ( ( rc = intelxl_alloc_admin ( intelxl, &intelxl->event ) ) != 0 )
  656. goto err_alloc_event;
  657. /* Allocate admin command queue */
  658. if ( ( rc = intelxl_alloc_admin ( intelxl, &intelxl->command ) ) != 0 )
  659. goto err_alloc_command;
  660. /* (Re)open admin queues */
  661. intelxl_reopen_admin ( intelxl );
  662. /* Get firmware version */
  663. if ( ( rc = intelxl_admin_version ( intelxl ) ) != 0 )
  664. goto err_version;
  665. /* Report driver version */
  666. if ( ( rc = intelxl_admin_driver ( intelxl ) ) != 0 )
  667. goto err_driver;
  668. return 0;
  669. err_driver:
  670. err_version:
  671. intelxl_disable_admin ( intelxl, &intelxl->command );
  672. intelxl_disable_admin ( intelxl, &intelxl->event );
  673. intelxl_free_admin ( intelxl, &intelxl->command );
  674. err_alloc_command:
  675. intelxl_free_admin ( intelxl, &intelxl->event );
  676. err_alloc_event:
  677. return rc;
  678. }
  679. /**
  680. * Reopen admin queues (after virtual function reset)
  681. *
  682. * @v intelxl Intel device
  683. */
  684. void intelxl_reopen_admin ( struct intelxl_nic *intelxl ) {
  685. unsigned int i;
  686. /* Enable admin event queue */
  687. intelxl_enable_admin ( intelxl, &intelxl->event );
  688. /* Enable admin command queue */
  689. intelxl_enable_admin ( intelxl, &intelxl->command );
  690. /* Initialise all admin event queue descriptors */
  691. for ( i = 0 ; i < INTELXL_ADMIN_NUM_DESC ; i++ )
  692. intelxl_admin_event_init ( intelxl, i );
  693. /* Post all descriptors to event queue */
  694. intelxl_refill_admin ( intelxl );
  695. }
  696. /**
  697. * Close admin queues
  698. *
  699. * @v intelxl Intel device
  700. */
  701. void intelxl_close_admin ( struct intelxl_nic *intelxl ) {
  702. /* Shut down admin queues */
  703. intelxl_admin_shutdown ( intelxl );
  704. /* Disable admin queues */
  705. intelxl_disable_admin ( intelxl, &intelxl->command );
  706. intelxl_disable_admin ( intelxl, &intelxl->event );
  707. /* Free admin queues */
  708. intelxl_free_admin ( intelxl, &intelxl->command );
  709. intelxl_free_admin ( intelxl, &intelxl->event );
  710. }
  711. /******************************************************************************
  712. *
  713. * Descriptor rings
  714. *
  715. ******************************************************************************
  716. */
  717. /**
  718. * Allocate descriptor ring
  719. *
  720. * @v intelxl Intel device
  721. * @v ring Descriptor ring
  722. * @ret rc Return status code
  723. */
  724. int intelxl_alloc_ring ( struct intelxl_nic *intelxl,
  725. struct intelxl_ring *ring ) {
  726. physaddr_t address;
  727. int rc;
  728. /* Allocate descriptor ring */
  729. ring->desc.raw = malloc_dma ( ring->len, INTELXL_ALIGN );
  730. if ( ! ring->desc.raw ) {
  731. rc = -ENOMEM;
  732. goto err_alloc;
  733. }
  734. address = virt_to_bus ( ring->desc.raw );
  735. /* Initialise descriptor ring */
  736. memset ( ring->desc.raw, 0, ring->len );
  737. /* Reset tail pointer */
  738. writel ( 0, ( intelxl->regs + ring->tail ) );
  739. /* Reset counters */
  740. ring->prod = 0;
  741. ring->cons = 0;
  742. DBGC ( intelxl, "INTELXL %p ring %06x is at [%08llx,%08llx)\n",
  743. intelxl, ( ring->reg + ring->tail ),
  744. ( ( unsigned long long ) address ),
  745. ( ( unsigned long long ) address + ring->len ) );
  746. return 0;
  747. free_dma ( ring->desc.raw, ring->len );
  748. err_alloc:
  749. return rc;
  750. }
  751. /**
  752. * Free descriptor ring
  753. *
  754. * @v intelxl Intel device
  755. * @v ring Descriptor ring
  756. */
  757. void intelxl_free_ring ( struct intelxl_nic *intelxl __unused,
  758. struct intelxl_ring *ring ) {
  759. /* Free descriptor ring */
  760. free_dma ( ring->desc.raw, ring->len );
  761. ring->desc.raw = NULL;
  762. }
  763. /**
  764. * Dump queue context (for debugging)
  765. *
  766. * @v intelxl Intel device
  767. * @v op Context operation
  768. * @v len Size of context
  769. */
  770. static __attribute__ (( unused )) void
  771. intelxl_context_dump ( struct intelxl_nic *intelxl, uint32_t op, size_t len ) {
  772. struct intelxl_context_line line;
  773. uint32_t pfcm_lanctxctl;
  774. uint32_t pfcm_lanctxstat;
  775. unsigned int queue;
  776. unsigned int index;
  777. unsigned int i;
  778. /* Do nothing unless debug output is enabled */
  779. if ( ! DBG_EXTRA )
  780. return;
  781. /* Dump context */
  782. DBGC2 ( intelxl, "INTELXL %p context %#08x:\n", intelxl, op );
  783. for ( index = 0 ; ( sizeof ( line ) * index ) < len ; index++ ) {
  784. /* Start context operation */
  785. queue = ( intelxl->base + intelxl->queue );
  786. pfcm_lanctxctl =
  787. ( INTELXL_PFCM_LANCTXCTL_QUEUE_NUM ( queue ) |
  788. INTELXL_PFCM_LANCTXCTL_SUB_LINE ( index ) |
  789. INTELXL_PFCM_LANCTXCTL_OP_CODE_READ | op );
  790. writel ( pfcm_lanctxctl,
  791. intelxl->regs + INTELXL_PFCM_LANCTXCTL );
  792. /* Wait for operation to complete */
  793. for ( i = 0 ; i < INTELXL_CTX_MAX_WAIT_MS ; i++ ) {
  794. /* Check if operation is complete */
  795. pfcm_lanctxstat = readl ( intelxl->regs +
  796. INTELXL_PFCM_LANCTXSTAT );
  797. if ( pfcm_lanctxstat & INTELXL_PFCM_LANCTXSTAT_DONE )
  798. break;
  799. /* Delay */
  800. mdelay ( 1 );
  801. }
  802. /* Read context data */
  803. for ( i = 0 ; i < ( sizeof ( line ) /
  804. sizeof ( line.raw[0] ) ) ; i++ ) {
  805. line.raw[i] = readl ( intelxl->regs +
  806. INTELXL_PFCM_LANCTXDATA ( i ) );
  807. }
  808. DBGC2_HDA ( intelxl, ( sizeof ( line ) * index ),
  809. &line, sizeof ( line ) );
  810. }
  811. }
  812. /**
  813. * Program queue context line
  814. *
  815. * @v intelxl Intel device
  816. * @v line Queue context line
  817. * @v index Line number
  818. * @v op Context operation
  819. * @ret rc Return status code
  820. */
  821. static int intelxl_context_line ( struct intelxl_nic *intelxl,
  822. struct intelxl_context_line *line,
  823. unsigned int index, uint32_t op ) {
  824. uint32_t pfcm_lanctxctl;
  825. uint32_t pfcm_lanctxstat;
  826. unsigned int queue;
  827. unsigned int i;
  828. /* Write context data */
  829. for ( i = 0; i < ( sizeof ( *line ) / sizeof ( line->raw[0] ) ); i++ ) {
  830. writel ( le32_to_cpu ( line->raw[i] ),
  831. intelxl->regs + INTELXL_PFCM_LANCTXDATA ( i ) );
  832. }
  833. /* Start context operation */
  834. queue = ( intelxl->base + intelxl->queue );
  835. pfcm_lanctxctl = ( INTELXL_PFCM_LANCTXCTL_QUEUE_NUM ( queue ) |
  836. INTELXL_PFCM_LANCTXCTL_SUB_LINE ( index ) |
  837. INTELXL_PFCM_LANCTXCTL_OP_CODE_WRITE | op );
  838. writel ( pfcm_lanctxctl, intelxl->regs + INTELXL_PFCM_LANCTXCTL );
  839. /* Wait for operation to complete */
  840. for ( i = 0 ; i < INTELXL_CTX_MAX_WAIT_MS ; i++ ) {
  841. /* Check if operation is complete */
  842. pfcm_lanctxstat = readl ( intelxl->regs +
  843. INTELXL_PFCM_LANCTXSTAT );
  844. if ( pfcm_lanctxstat & INTELXL_PFCM_LANCTXSTAT_DONE )
  845. return 0;
  846. /* Delay */
  847. mdelay ( 1 );
  848. }
  849. DBGC ( intelxl, "INTELXL %p timed out waiting for context: %#08x\n",
  850. intelxl, pfcm_lanctxctl );
  851. return -ETIMEDOUT;
  852. }
  853. /**
  854. * Program queue context
  855. *
  856. * @v intelxl Intel device
  857. * @v line Queue context lines
  858. * @v len Size of context
  859. * @v op Context operation
  860. * @ret rc Return status code
  861. */
  862. static int intelxl_context ( struct intelxl_nic *intelxl,
  863. struct intelxl_context_line *line,
  864. size_t len, uint32_t op ) {
  865. unsigned int index;
  866. int rc;
  867. DBGC2 ( intelxl, "INTELXL %p context %#08x len %#zx:\n",
  868. intelxl, op, len );
  869. DBGC2_HDA ( intelxl, 0, line, len );
  870. /* Program one line at a time */
  871. for ( index = 0 ; ( sizeof ( *line ) * index ) < len ; index++ ) {
  872. if ( ( rc = intelxl_context_line ( intelxl, line++, index,
  873. op ) ) != 0 )
  874. return rc;
  875. }
  876. return 0;
  877. }
  878. /**
  879. * Program transmit queue context
  880. *
  881. * @v intelxl Intel device
  882. * @v address Descriptor ring base address
  883. * @ret rc Return status code
  884. */
  885. static int intelxl_context_tx ( struct intelxl_nic *intelxl,
  886. physaddr_t address ) {
  887. union {
  888. struct intelxl_context_tx tx;
  889. struct intelxl_context_line line;
  890. } ctx;
  891. int rc;
  892. /* Initialise context */
  893. memset ( &ctx, 0, sizeof ( ctx ) );
  894. ctx.tx.flags = cpu_to_le16 ( INTELXL_CTX_TX_FL_NEW );
  895. ctx.tx.base = cpu_to_le64 ( INTELXL_CTX_TX_BASE ( address ) );
  896. ctx.tx.count =
  897. cpu_to_le16 ( INTELXL_CTX_TX_COUNT ( INTELXL_TX_NUM_DESC ) );
  898. ctx.tx.qset = INTELXL_CTX_TX_QSET ( intelxl->qset );
  899. /* Program context */
  900. if ( ( rc = intelxl_context ( intelxl, &ctx.line, sizeof ( ctx ),
  901. INTELXL_PFCM_LANCTXCTL_TYPE_TX ) ) != 0 )
  902. return rc;
  903. return 0;
  904. }
  905. /**
  906. * Program receive queue context
  907. *
  908. * @v intelxl Intel device
  909. * @v address Descriptor ring base address
  910. * @ret rc Return status code
  911. */
  912. static int intelxl_context_rx ( struct intelxl_nic *intelxl,
  913. physaddr_t address ) {
  914. union {
  915. struct intelxl_context_rx rx;
  916. struct intelxl_context_line line;
  917. } ctx;
  918. uint64_t base_count;
  919. int rc;
  920. /* Initialise context */
  921. memset ( &ctx, 0, sizeof ( ctx ) );
  922. base_count = INTELXL_CTX_RX_BASE_COUNT ( address, INTELXL_RX_NUM_DESC );
  923. ctx.rx.base_count = cpu_to_le64 ( base_count );
  924. ctx.rx.len = cpu_to_le16 ( INTELXL_CTX_RX_LEN ( intelxl->mfs ) );
  925. ctx.rx.flags = ( INTELXL_CTX_RX_FL_DSIZE | INTELXL_CTX_RX_FL_CRCSTRIP );
  926. ctx.rx.mfs = cpu_to_le16 ( INTELXL_CTX_RX_MFS ( intelxl->mfs ) );
  927. /* Program context */
  928. if ( ( rc = intelxl_context ( intelxl, &ctx.line, sizeof ( ctx ),
  929. INTELXL_PFCM_LANCTXCTL_TYPE_RX ) ) != 0 )
  930. return rc;
  931. return 0;
  932. }
  933. /**
  934. * Enable descriptor ring
  935. *
  936. * @v intelxl Intel device
  937. * @v ring Descriptor ring
  938. * @ret rc Return status code
  939. */
  940. static int intelxl_enable_ring ( struct intelxl_nic *intelxl,
  941. struct intelxl_ring *ring ) {
  942. void *ring_regs = ( intelxl->regs + ring->reg );
  943. uint32_t qxx_ena;
  944. /* Enable ring */
  945. writel ( INTELXL_QXX_ENA_REQ, ( ring_regs + INTELXL_QXX_ENA ) );
  946. udelay ( INTELXL_QUEUE_ENABLE_DELAY_US );
  947. qxx_ena = readl ( ring_regs + INTELXL_QXX_ENA );
  948. if ( ! ( qxx_ena & INTELXL_QXX_ENA_STAT ) ) {
  949. DBGC ( intelxl, "INTELXL %p ring %06x failed to enable: "
  950. "%#08x\n", intelxl, ring->reg, qxx_ena );
  951. return -EIO;
  952. }
  953. return 0;
  954. }
  955. /**
  956. * Disable descriptor ring
  957. *
  958. * @v intelxl Intel device
  959. * @v ring Descriptor ring
  960. * @ret rc Return status code
  961. */
  962. static int intelxl_disable_ring ( struct intelxl_nic *intelxl,
  963. struct intelxl_ring *ring ) {
  964. void *ring_regs = ( intelxl->regs + ring->reg );
  965. uint32_t qxx_ena;
  966. unsigned int i;
  967. /* Disable ring */
  968. writel ( 0, ( ring_regs + INTELXL_QXX_ENA ) );
  969. /* Wait for ring to be disabled */
  970. for ( i = 0 ; i < INTELXL_QUEUE_DISABLE_MAX_WAIT_MS ; i++ ) {
  971. /* Check if ring is disabled */
  972. qxx_ena = readl ( ring_regs + INTELXL_QXX_ENA );
  973. if ( ! ( qxx_ena & INTELXL_QXX_ENA_STAT ) )
  974. return 0;
  975. /* Delay */
  976. mdelay ( 1 );
  977. }
  978. DBGC ( intelxl, "INTELXL %p ring %06x timed out waiting for disable: "
  979. "%#08x\n", intelxl, ring->reg, qxx_ena );
  980. return -ETIMEDOUT;
  981. }
  982. /**
  983. * Create descriptor ring
  984. *
  985. * @v intelxl Intel device
  986. * @v ring Descriptor ring
  987. * @ret rc Return status code
  988. */
  989. static int intelxl_create_ring ( struct intelxl_nic *intelxl,
  990. struct intelxl_ring *ring ) {
  991. physaddr_t address;
  992. int rc;
  993. /* Allocate descriptor ring */
  994. if ( ( rc = intelxl_alloc_ring ( intelxl, ring ) ) != 0 )
  995. goto err_alloc;
  996. /* Program queue context */
  997. address = virt_to_bus ( ring->desc.raw );
  998. if ( ( rc = ring->context ( intelxl, address ) ) != 0 )
  999. goto err_context;
  1000. /* Enable ring */
  1001. if ( ( rc = intelxl_enable_ring ( intelxl, ring ) ) != 0 )
  1002. goto err_enable;
  1003. return 0;
  1004. intelxl_disable_ring ( intelxl, ring );
  1005. err_enable:
  1006. err_context:
  1007. intelxl_free_ring ( intelxl, ring );
  1008. err_alloc:
  1009. return rc;
  1010. }
  1011. /**
  1012. * Destroy descriptor ring
  1013. *
  1014. * @v intelxl Intel device
  1015. * @v ring Descriptor ring
  1016. */
  1017. static void intelxl_destroy_ring ( struct intelxl_nic *intelxl,
  1018. struct intelxl_ring *ring ) {
  1019. int rc;
  1020. /* Disable ring */
  1021. if ( ( rc = intelxl_disable_ring ( intelxl, ring ) ) != 0 ) {
  1022. /* Leak memory; there's nothing else we can do */
  1023. return;
  1024. }
  1025. /* Free descriptor ring */
  1026. intelxl_free_ring ( intelxl, ring );
  1027. }
  1028. /**
  1029. * Refill receive descriptor ring
  1030. *
  1031. * @v intelxl Intel device
  1032. */
  1033. static void intelxl_refill_rx ( struct intelxl_nic *intelxl ) {
  1034. struct intelxl_rx_data_descriptor *rx;
  1035. struct io_buffer *iobuf;
  1036. unsigned int rx_idx;
  1037. unsigned int rx_tail;
  1038. physaddr_t address;
  1039. unsigned int refilled = 0;
  1040. /* Refill ring */
  1041. while ( ( intelxl->rx.prod - intelxl->rx.cons ) < INTELXL_RX_FILL ) {
  1042. /* Allocate I/O buffer */
  1043. iobuf = alloc_iob ( intelxl->mfs );
  1044. if ( ! iobuf ) {
  1045. /* Wait for next refill */
  1046. break;
  1047. }
  1048. /* Get next receive descriptor */
  1049. rx_idx = ( intelxl->rx.prod++ % INTELXL_RX_NUM_DESC );
  1050. rx = &intelxl->rx.desc.rx[rx_idx].data;
  1051. /* Populate receive descriptor */
  1052. address = virt_to_bus ( iobuf->data );
  1053. rx->address = cpu_to_le64 ( address );
  1054. rx->flags = 0;
  1055. /* Record I/O buffer */
  1056. assert ( intelxl->rx_iobuf[rx_idx] == NULL );
  1057. intelxl->rx_iobuf[rx_idx] = iobuf;
  1058. DBGC2 ( intelxl, "INTELXL %p RX %d is [%llx,%llx)\n", intelxl,
  1059. rx_idx, ( ( unsigned long long ) address ),
  1060. ( ( unsigned long long ) address + intelxl->mfs ) );
  1061. refilled++;
  1062. }
  1063. /* Push descriptors to card, if applicable */
  1064. if ( refilled ) {
  1065. wmb();
  1066. rx_tail = ( intelxl->rx.prod % INTELXL_RX_NUM_DESC );
  1067. writel ( rx_tail, ( intelxl->regs + intelxl->rx.tail ) );
  1068. }
  1069. }
  1070. /**
  1071. * Discard unused receive I/O buffers
  1072. *
  1073. * @v intelxl Intel device
  1074. */
  1075. void intelxl_empty_rx ( struct intelxl_nic *intelxl ) {
  1076. unsigned int i;
  1077. /* Discard any unused receive buffers */
  1078. for ( i = 0 ; i < INTELXL_RX_NUM_DESC ; i++ ) {
  1079. if ( intelxl->rx_iobuf[i] )
  1080. free_iob ( intelxl->rx_iobuf[i] );
  1081. intelxl->rx_iobuf[i] = NULL;
  1082. }
  1083. }
  1084. /******************************************************************************
  1085. *
  1086. * Network device interface
  1087. *
  1088. ******************************************************************************
  1089. */
  1090. /**
  1091. * Open network device
  1092. *
  1093. * @v netdev Network device
  1094. * @ret rc Return status code
  1095. */
  1096. static int intelxl_open ( struct net_device *netdev ) {
  1097. struct intelxl_nic *intelxl = netdev->priv;
  1098. union intelxl_receive_address mac;
  1099. unsigned int queue;
  1100. uint32_t prtgl_sal;
  1101. uint32_t prtgl_sah;
  1102. int rc;
  1103. /* Calculate maximum frame size */
  1104. intelxl->mfs = ( ( ETH_HLEN + netdev->mtu + 4 /* CRC */ +
  1105. INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) );
  1106. /* Program MAC address and maximum frame size */
  1107. memset ( &mac, 0, sizeof ( mac ) );
  1108. memcpy ( mac.raw, netdev->ll_addr, sizeof ( mac.raw ) );
  1109. prtgl_sal = le32_to_cpu ( mac.reg.low );
  1110. prtgl_sah = ( le32_to_cpu ( mac.reg.high ) |
  1111. INTELXL_PRTGL_SAH_MFS_SET ( intelxl->mfs ) );
  1112. writel ( prtgl_sal, intelxl->regs + INTELXL_PRTGL_SAL );
  1113. writel ( prtgl_sah, intelxl->regs + INTELXL_PRTGL_SAH );
  1114. /* Associate transmit queue to PF */
  1115. writel ( ( INTELXL_QXX_CTL_PFVF_Q_PF |
  1116. INTELXL_QXX_CTL_PFVF_PF_INDX ( intelxl->pf ) ),
  1117. ( intelxl->regs + intelxl->tx.reg + INTELXL_QXX_CTL ) );
  1118. /* Clear transmit pre queue disable */
  1119. queue = ( intelxl->base + intelxl->queue );
  1120. writel ( ( INTELXL_GLLAN_TXPRE_QDIS_CLEAR_QDIS |
  1121. INTELXL_GLLAN_TXPRE_QDIS_QINDX ( queue ) ),
  1122. ( intelxl->regs + INTELXL_GLLAN_TXPRE_QDIS ( queue ) ) );
  1123. /* Reset transmit queue head */
  1124. writel ( 0, ( intelxl->regs + INTELXL_QTX_HEAD ( intelxl->queue ) ) );
  1125. /* Create receive descriptor ring */
  1126. if ( ( rc = intelxl_create_ring ( intelxl, &intelxl->rx ) ) != 0 )
  1127. goto err_create_rx;
  1128. /* Create transmit descriptor ring */
  1129. if ( ( rc = intelxl_create_ring ( intelxl, &intelxl->tx ) ) != 0 )
  1130. goto err_create_tx;
  1131. /* Fill receive ring */
  1132. intelxl_refill_rx ( intelxl );
  1133. /* Restart autonegotiation */
  1134. intelxl_admin_autoneg ( intelxl );
  1135. /* Update link state */
  1136. intelxl_admin_link ( netdev );
  1137. return 0;
  1138. writel ( ( INTELXL_GLLAN_TXPRE_QDIS_SET_QDIS |
  1139. INTELXL_GLLAN_TXPRE_QDIS_QINDX ( queue ) ),
  1140. ( intelxl->regs + INTELXL_GLLAN_TXPRE_QDIS ( queue ) ) );
  1141. udelay ( INTELXL_QUEUE_PRE_DISABLE_DELAY_US );
  1142. intelxl_destroy_ring ( intelxl, &intelxl->tx );
  1143. err_create_tx:
  1144. intelxl_destroy_ring ( intelxl, &intelxl->rx );
  1145. err_create_rx:
  1146. return rc;
  1147. }
  1148. /**
  1149. * Close network device
  1150. *
  1151. * @v netdev Network device
  1152. */
  1153. static void intelxl_close ( struct net_device *netdev ) {
  1154. struct intelxl_nic *intelxl = netdev->priv;
  1155. unsigned int queue;
  1156. /* Dump contexts (for debugging) */
  1157. intelxl_context_dump ( intelxl, INTELXL_PFCM_LANCTXCTL_TYPE_TX,
  1158. sizeof ( struct intelxl_context_tx ) );
  1159. intelxl_context_dump ( intelxl, INTELXL_PFCM_LANCTXCTL_TYPE_RX,
  1160. sizeof ( struct intelxl_context_rx ) );
  1161. /* Pre-disable transmit queue */
  1162. queue = ( intelxl->base + intelxl->queue );
  1163. writel ( ( INTELXL_GLLAN_TXPRE_QDIS_SET_QDIS |
  1164. INTELXL_GLLAN_TXPRE_QDIS_QINDX ( queue ) ),
  1165. ( intelxl->regs + INTELXL_GLLAN_TXPRE_QDIS ( queue ) ) );
  1166. udelay ( INTELXL_QUEUE_PRE_DISABLE_DELAY_US );
  1167. /* Destroy transmit descriptor ring */
  1168. intelxl_destroy_ring ( intelxl, &intelxl->tx );
  1169. /* Destroy receive descriptor ring */
  1170. intelxl_destroy_ring ( intelxl, &intelxl->rx );
  1171. /* Discard any unused receive buffers */
  1172. intelxl_empty_rx ( intelxl );
  1173. }
  1174. /**
  1175. * Transmit packet
  1176. *
  1177. * @v netdev Network device
  1178. * @v iobuf I/O buffer
  1179. * @ret rc Return status code
  1180. */
  1181. int intelxl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
  1182. struct intelxl_nic *intelxl = netdev->priv;
  1183. struct intelxl_tx_data_descriptor *tx;
  1184. unsigned int tx_idx;
  1185. unsigned int tx_tail;
  1186. physaddr_t address;
  1187. size_t len;
  1188. /* Get next transmit descriptor */
  1189. if ( ( intelxl->tx.prod - intelxl->tx.cons ) >= INTELXL_TX_FILL ) {
  1190. DBGC ( intelxl, "INTELXL %p out of transmit descriptors\n",
  1191. intelxl );
  1192. return -ENOBUFS;
  1193. }
  1194. tx_idx = ( intelxl->tx.prod++ % INTELXL_TX_NUM_DESC );
  1195. tx_tail = ( intelxl->tx.prod % INTELXL_TX_NUM_DESC );
  1196. tx = &intelxl->tx.desc.tx[tx_idx].data;
  1197. /* Populate transmit descriptor */
  1198. address = virt_to_bus ( iobuf->data );
  1199. len = iob_len ( iobuf );
  1200. tx->address = cpu_to_le64 ( address );
  1201. tx->len = cpu_to_le32 ( INTELXL_TX_DATA_LEN ( len ) );
  1202. tx->flags = cpu_to_le32 ( INTELXL_TX_DATA_DTYP | INTELXL_TX_DATA_EOP |
  1203. INTELXL_TX_DATA_RS | INTELXL_TX_DATA_JFDI );
  1204. wmb();
  1205. /* Notify card that there are packets ready to transmit */
  1206. writel ( tx_tail, ( intelxl->regs + intelxl->tx.tail ) );
  1207. DBGC2 ( intelxl, "INTELXL %p TX %d is [%llx,%llx)\n", intelxl, tx_idx,
  1208. ( ( unsigned long long ) address ),
  1209. ( ( unsigned long long ) address + len ) );
  1210. return 0;
  1211. }
  1212. /**
  1213. * Poll for completed packets
  1214. *
  1215. * @v netdev Network device
  1216. */
  1217. static void intelxl_poll_tx ( struct net_device *netdev ) {
  1218. struct intelxl_nic *intelxl = netdev->priv;
  1219. struct intelxl_tx_writeback_descriptor *tx_wb;
  1220. unsigned int tx_idx;
  1221. /* Check for completed packets */
  1222. while ( intelxl->tx.cons != intelxl->tx.prod ) {
  1223. /* Get next transmit descriptor */
  1224. tx_idx = ( intelxl->tx.cons % INTELXL_TX_NUM_DESC );
  1225. tx_wb = &intelxl->tx.desc.tx[tx_idx].wb;
  1226. /* Stop if descriptor is still in use */
  1227. if ( ! ( tx_wb->flags & INTELXL_TX_WB_FL_DD ) )
  1228. return;
  1229. DBGC2 ( intelxl, "INTELXL %p TX %d complete\n",
  1230. intelxl, tx_idx );
  1231. /* Complete TX descriptor */
  1232. netdev_tx_complete_next ( netdev );
  1233. intelxl->tx.cons++;
  1234. }
  1235. }
  1236. /**
  1237. * Poll for received packets
  1238. *
  1239. * @v netdev Network device
  1240. */
  1241. static void intelxl_poll_rx ( struct net_device *netdev ) {
  1242. struct intelxl_nic *intelxl = netdev->priv;
  1243. struct intelxl_rx_writeback_descriptor *rx_wb;
  1244. struct io_buffer *iobuf;
  1245. unsigned int rx_idx;
  1246. unsigned int tag;
  1247. size_t len;
  1248. /* Check for received packets */
  1249. while ( intelxl->rx.cons != intelxl->rx.prod ) {
  1250. /* Get next receive descriptor */
  1251. rx_idx = ( intelxl->rx.cons % INTELXL_RX_NUM_DESC );
  1252. rx_wb = &intelxl->rx.desc.rx[rx_idx].wb;
  1253. /* Stop if descriptor is still in use */
  1254. if ( ! ( rx_wb->flags & cpu_to_le32 ( INTELXL_RX_WB_FL_DD ) ) )
  1255. return;
  1256. /* Populate I/O buffer */
  1257. iobuf = intelxl->rx_iobuf[rx_idx];
  1258. intelxl->rx_iobuf[rx_idx] = NULL;
  1259. len = INTELXL_RX_WB_LEN ( le32_to_cpu ( rx_wb->len ) );
  1260. iob_put ( iobuf, len );
  1261. /* Find VLAN device, if applicable */
  1262. if ( rx_wb->flags & cpu_to_le32 ( INTELXL_RX_WB_FL_VLAN ) ) {
  1263. tag = VLAN_TAG ( le16_to_cpu ( rx_wb->vlan ) );
  1264. } else {
  1265. tag = 0;
  1266. }
  1267. /* Hand off to network stack */
  1268. if ( rx_wb->flags & cpu_to_le32 ( INTELXL_RX_WB_FL_RXE ) ) {
  1269. DBGC ( intelxl, "INTELXL %p RX %d error (length %zd, "
  1270. "flags %08x)\n", intelxl, rx_idx, len,
  1271. le32_to_cpu ( rx_wb->flags ) );
  1272. vlan_netdev_rx_err ( netdev, tag, iobuf, -EIO );
  1273. } else {
  1274. DBGC2 ( intelxl, "INTELXL %p RX %d complete (length "
  1275. "%zd)\n", intelxl, rx_idx, len );
  1276. vlan_netdev_rx ( netdev, tag, iobuf );
  1277. }
  1278. intelxl->rx.cons++;
  1279. }
  1280. }
  1281. /**
  1282. * Poll for completed and received packets
  1283. *
  1284. * @v netdev Network device
  1285. */
  1286. void intelxl_poll ( struct net_device *netdev ) {
  1287. struct intelxl_nic *intelxl = netdev->priv;
  1288. /* Acknowledge interrupts, if applicable */
  1289. if ( netdev_irq_enabled ( netdev ) ) {
  1290. writel ( ( INTELXL_INT_DYN_CTL_CLEARPBA |
  1291. INTELXL_INT_DYN_CTL_INTENA_MASK ),
  1292. ( intelxl->regs + intelxl->intr ) );
  1293. }
  1294. /* Poll for completed packets */
  1295. intelxl_poll_tx ( netdev );
  1296. /* Poll for received packets */
  1297. intelxl_poll_rx ( netdev );
  1298. /* Poll for admin events */
  1299. intelxl_poll_admin ( netdev );
  1300. /* Refill RX ring */
  1301. intelxl_refill_rx ( intelxl );
  1302. }
  1303. /**
  1304. * Enable or disable interrupts
  1305. *
  1306. * @v netdev Network device
  1307. * @v enable Interrupts should be enabled
  1308. */
  1309. static void intelxl_irq ( struct net_device *netdev, int enable ) {
  1310. struct intelxl_nic *intelxl = netdev->priv;
  1311. writel ( ( enable ? INTELXL_INT_DYN_CTL_INTENA : 0 ),
  1312. ( intelxl->regs + intelxl->intr ) );
  1313. }
  1314. /** Network device operations */
  1315. static struct net_device_operations intelxl_operations = {
  1316. .open = intelxl_open,
  1317. .close = intelxl_close,
  1318. .transmit = intelxl_transmit,
  1319. .poll = intelxl_poll,
  1320. .irq = intelxl_irq,
  1321. };
  1322. /******************************************************************************
  1323. *
  1324. * PCI interface
  1325. *
  1326. ******************************************************************************
  1327. */
  1328. /**
  1329. * Probe PCI device
  1330. *
  1331. * @v pci PCI device
  1332. * @ret rc Return status code
  1333. */
  1334. static int intelxl_probe ( struct pci_device *pci ) {
  1335. struct net_device *netdev;
  1336. struct intelxl_nic *intelxl;
  1337. uint32_t pfgen_portnum;
  1338. uint32_t pflan_qalloc;
  1339. int rc;
  1340. /* Allocate and initialise net device */
  1341. netdev = alloc_etherdev ( sizeof ( *intelxl ) );
  1342. if ( ! netdev ) {
  1343. rc = -ENOMEM;
  1344. goto err_alloc;
  1345. }
  1346. netdev_init ( netdev, &intelxl_operations );
  1347. intelxl = netdev->priv;
  1348. pci_set_drvdata ( pci, netdev );
  1349. netdev->dev = &pci->dev;
  1350. memset ( intelxl, 0, sizeof ( *intelxl ) );
  1351. intelxl->pf = PCI_FUNC ( pci->busdevfn );
  1352. intelxl->intr = INTELXL_PFINT_DYN_CTL0;
  1353. intelxl_init_admin ( &intelxl->command, INTELXL_ADMIN_CMD,
  1354. &intelxl_admin_offsets );
  1355. intelxl_init_admin ( &intelxl->event, INTELXL_ADMIN_EVT,
  1356. &intelxl_admin_offsets );
  1357. intelxl_init_ring ( &intelxl->tx, INTELXL_TX_NUM_DESC,
  1358. sizeof ( intelxl->tx.desc.tx[0] ),
  1359. intelxl_context_tx );
  1360. intelxl_init_ring ( &intelxl->rx, INTELXL_RX_NUM_DESC,
  1361. sizeof ( intelxl->rx.desc.rx[0] ),
  1362. intelxl_context_rx );
  1363. /* Fix up PCI device */
  1364. adjust_pci_device ( pci );
  1365. /* Map registers */
  1366. intelxl->regs = ioremap ( pci->membase, INTELXL_BAR_SIZE );
  1367. if ( ! intelxl->regs ) {
  1368. rc = -ENODEV;
  1369. goto err_ioremap;
  1370. }
  1371. /* Reset the NIC */
  1372. if ( ( rc = intelxl_reset ( intelxl ) ) != 0 )
  1373. goto err_reset;
  1374. /* Get port number and base queue number */
  1375. pfgen_portnum = readl ( intelxl->regs + INTELXL_PFGEN_PORTNUM );
  1376. intelxl->port = INTELXL_PFGEN_PORTNUM_PORT_NUM ( pfgen_portnum );
  1377. pflan_qalloc = readl ( intelxl->regs + INTELXL_PFLAN_QALLOC );
  1378. intelxl->base = INTELXL_PFLAN_QALLOC_FIRSTQ ( pflan_qalloc );
  1379. DBGC ( intelxl, "INTELXL %p PF %d using port %d queues [%#04x-%#04x]\n",
  1380. intelxl, intelxl->pf, intelxl->port, intelxl->base,
  1381. INTELXL_PFLAN_QALLOC_LASTQ ( pflan_qalloc ) );
  1382. /* Fetch MAC address and maximum frame size */
  1383. if ( ( rc = intelxl_fetch_mac ( intelxl, netdev ) ) != 0 )
  1384. goto err_fetch_mac;
  1385. /* Open admin queues */
  1386. if ( ( rc = intelxl_open_admin ( intelxl ) ) != 0 )
  1387. goto err_open_admin;
  1388. /* Get switch configuration */
  1389. if ( ( rc = intelxl_admin_switch ( intelxl ) ) != 0 )
  1390. goto err_admin_switch;
  1391. /* Get VSI configuration */
  1392. if ( ( rc = intelxl_admin_vsi ( intelxl ) ) != 0 )
  1393. goto err_admin_vsi;
  1394. /* Configure switch for promiscuous mode */
  1395. if ( ( rc = intelxl_admin_promisc ( intelxl ) ) != 0 )
  1396. goto err_admin_promisc;
  1397. /* Configure queue register addresses */
  1398. intelxl->tx.reg = INTELXL_QTX ( intelxl->queue );
  1399. intelxl->tx.tail = ( intelxl->tx.reg + INTELXL_QXX_TAIL );
  1400. intelxl->rx.reg = INTELXL_QRX ( intelxl->queue );
  1401. intelxl->rx.tail = ( intelxl->rx.reg + INTELXL_QXX_TAIL );
  1402. /* Configure interrupt causes */
  1403. writel ( ( INTELXL_QINT_TQCTL_NEXTQ_INDX_NONE |
  1404. INTELXL_QINT_TQCTL_CAUSE_ENA ),
  1405. intelxl->regs + INTELXL_QINT_TQCTL ( intelxl->queue ) );
  1406. writel ( ( INTELXL_QINT_RQCTL_NEXTQ_INDX ( intelxl->queue ) |
  1407. INTELXL_QINT_RQCTL_NEXTQ_TYPE_TX |
  1408. INTELXL_QINT_RQCTL_CAUSE_ENA ),
  1409. intelxl->regs + INTELXL_QINT_RQCTL ( intelxl->queue ) );
  1410. writel ( ( INTELXL_PFINT_LNKLST0_FIRSTQ_INDX ( intelxl->queue ) |
  1411. INTELXL_PFINT_LNKLST0_FIRSTQ_TYPE_RX ),
  1412. intelxl->regs + INTELXL_PFINT_LNKLST0 );
  1413. writel ( INTELXL_PFINT_ICR0_ENA_ADMINQ,
  1414. intelxl->regs + INTELXL_PFINT_ICR0_ENA );
  1415. /* Register network device */
  1416. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  1417. goto err_register_netdev;
  1418. /* Set initial link state */
  1419. intelxl_admin_link ( netdev );
  1420. return 0;
  1421. unregister_netdev ( netdev );
  1422. err_register_netdev:
  1423. err_admin_promisc:
  1424. err_admin_vsi:
  1425. err_admin_switch:
  1426. intelxl_close_admin ( intelxl );
  1427. err_open_admin:
  1428. err_fetch_mac:
  1429. intelxl_reset ( intelxl );
  1430. err_reset:
  1431. iounmap ( intelxl->regs );
  1432. err_ioremap:
  1433. netdev_nullify ( netdev );
  1434. netdev_put ( netdev );
  1435. err_alloc:
  1436. return rc;
  1437. }
  1438. /**
  1439. * Remove PCI device
  1440. *
  1441. * @v pci PCI device
  1442. */
  1443. static void intelxl_remove ( struct pci_device *pci ) {
  1444. struct net_device *netdev = pci_get_drvdata ( pci );
  1445. struct intelxl_nic *intelxl = netdev->priv;
  1446. /* Unregister network device */
  1447. unregister_netdev ( netdev );
  1448. /* Close admin queues */
  1449. intelxl_close_admin ( intelxl );
  1450. /* Reset the NIC */
  1451. intelxl_reset ( intelxl );
  1452. /* Free network device */
  1453. iounmap ( intelxl->regs );
  1454. netdev_nullify ( netdev );
  1455. netdev_put ( netdev );
  1456. }
  1457. /** PCI device IDs */
  1458. static struct pci_device_id intelxl_nics[] = {
  1459. PCI_ROM ( 0x8086, 0x1572, "x710-sfp", "X710 10GbE SFP+", 0 ),
  1460. PCI_ROM ( 0x8086, 0x1574, "xl710-qemu", "Virtual XL710", 0 ),
  1461. PCI_ROM ( 0x8086, 0x1580, "xl710-kx-b", "XL710 40GbE backplane", 0 ),
  1462. PCI_ROM ( 0x8086, 0x1581, "xl710-kx-c", "XL710 10GbE backplane", 0 ),
  1463. PCI_ROM ( 0x8086, 0x1583, "xl710-qda2", "XL710 40GbE QSFP+", 0 ),
  1464. PCI_ROM ( 0x8086, 0x1584, "xl710-qda1", "XL710 40GbE QSFP+", 0 ),
  1465. PCI_ROM ( 0x8086, 0x1585, "x710-qsfp", "X710 10GbE QSFP+", 0 ),
  1466. PCI_ROM ( 0x8086, 0x1586, "x710-10gt", "X710 10GBASE-T", 0 ),
  1467. PCI_ROM ( 0x8086, 0x1587, "x710-kr2", "XL710 20GbE backplane", 0 ),
  1468. PCI_ROM ( 0x8086, 0x1588, "x710-kr2-a", "XL710 20GbE backplane", 0 ),
  1469. PCI_ROM ( 0x8086, 0x1589, "x710-10gt4", "X710 10GBASE-T4", 0 ),
  1470. PCI_ROM ( 0x8086, 0x158a, "xxv710", "XXV710 25GbE backplane", 0 ),
  1471. PCI_ROM ( 0x8086, 0x158b, "xxv710-sfp28", "XXV710 25GbE SFP28", 0 ),
  1472. PCI_ROM ( 0x8086, 0x37ce, "x722-kx", "X722 10GbE backplane", 0 ),
  1473. PCI_ROM ( 0x8086, 0x37cf, "x722-qsfp", "X722 10GbE QSFP+", 0 ),
  1474. PCI_ROM ( 0x8086, 0x37d0, "x722-sfp", "X722 10GbE SFP+", 0 ),
  1475. PCI_ROM ( 0x8086, 0x37d1, "x722-1gt", "X722 1GBASE-T", 0 ),
  1476. PCI_ROM ( 0x8086, 0x37d2, "x722-10gt", "X722 10GBASE-T", 0 ),
  1477. PCI_ROM ( 0x8086, 0x37d3, "x722-sfp-i", "X722 10GbE SFP+", 0 ),
  1478. };
  1479. /** PCI driver */
  1480. struct pci_driver intelxl_driver __pci_driver = {
  1481. .ids = intelxl_nics,
  1482. .id_count = ( sizeof ( intelxl_nics ) / sizeof ( intelxl_nics[0] ) ),
  1483. .probe = intelxl_probe,
  1484. .remove = intelxl_remove,
  1485. };