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

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