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 50KB

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