cxgb2.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /*****************************************************************************
  2. * *
  3. * File: cxgb2.c *
  4. * $Revision: 1.25 $ *
  5. * $Date: 2005/06/22 00:43:25 $ *
  6. * Description: *
  7. * Chelsio 10Gb Ethernet Driver. *
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License, version 2, as *
  11. * published by the Free Software Foundation. *
  12. * *
  13. * You should have received a copy of the GNU General Public License along *
  14. * with this program; if not, write to the Free Software Foundation, Inc., *
  15. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  16. * *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * http://www.chelsio.com *
  22. * *
  23. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  24. * All rights reserved. *
  25. * *
  26. * Maintainers: maintainers@chelsio.com *
  27. * *
  28. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  29. * Tina Yang <tainay@chelsio.com> *
  30. * Felix Marti <felix@chelsio.com> *
  31. * Scott Bardone <sbardone@chelsio.com> *
  32. * Kurt Ottaway <kottaway@chelsio.com> *
  33. * Frank DiMambro <frank@chelsio.com> *
  34. * *
  35. * History: *
  36. * *
  37. ****************************************************************************/
  38. #include "common.h"
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/pci.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_vlan.h>
  45. #include <linux/mii.h>
  46. #include <linux/sockios.h>
  47. #include <linux/proc_fs.h>
  48. #include <linux/dma-mapping.h>
  49. #include <asm/uaccess.h>
  50. #include "cpl5_cmd.h"
  51. #include "regs.h"
  52. #include "gmac.h"
  53. #include "cphy.h"
  54. #include "sge.h"
  55. #include "espi.h"
  56. #ifdef work_struct
  57. #include <linux/tqueue.h>
  58. #define INIT_WORK INIT_TQUEUE
  59. #define schedule_work schedule_task
  60. #define flush_scheduled_work flush_scheduled_tasks
  61. static inline void schedule_mac_stats_update(struct adapter *ap, int secs)
  62. {
  63. mod_timer(&ap->stats_update_timer, jiffies + secs * HZ);
  64. }
  65. static inline void cancel_mac_stats_update(struct adapter *ap)
  66. {
  67. del_timer_sync(&ap->stats_update_timer);
  68. flush_scheduled_tasks();
  69. }
  70. /*
  71. * Stats update timer for 2.4. It schedules a task to do the actual update as
  72. * we need to access MAC statistics in process context.
  73. */
  74. static void mac_stats_timer(unsigned long data)
  75. {
  76. struct adapter *ap = (struct adapter *)data;
  77. schedule_task(&ap->stats_update_task);
  78. }
  79. #else
  80. #include <linux/workqueue.h>
  81. static inline void schedule_mac_stats_update(struct adapter *ap, int secs)
  82. {
  83. schedule_delayed_work(&ap->stats_update_task, secs * HZ);
  84. }
  85. static inline void cancel_mac_stats_update(struct adapter *ap)
  86. {
  87. cancel_delayed_work(&ap->stats_update_task);
  88. }
  89. #endif
  90. #define MAX_CMDQ_ENTRIES 16384
  91. #define MAX_CMDQ1_ENTRIES 1024
  92. #define MAX_RX_BUFFERS 16384
  93. #define MAX_RX_JUMBO_BUFFERS 16384
  94. #define MAX_TX_BUFFERS_HIGH 16384U
  95. #define MAX_TX_BUFFERS_LOW 1536U
  96. #define MIN_FL_ENTRIES 32
  97. #define PORT_MASK ((1 << MAX_NPORTS) - 1)
  98. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  99. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  100. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  101. /*
  102. * The EEPROM is actually bigger but only the first few bytes are used so we
  103. * only report those.
  104. */
  105. #define EEPROM_SIZE 32
  106. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  107. MODULE_AUTHOR("Chelsio Communications");
  108. MODULE_LICENSE("GPL");
  109. static int dflt_msg_enable = DFLT_MSG_ENABLE;
  110. module_param(dflt_msg_enable, int, 0);
  111. MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T1 message enable bitmap");
  112. static const char pci_speed[][4] = {
  113. "33", "66", "100", "133"
  114. };
  115. /*
  116. * Setup MAC to receive the types of packets we want.
  117. */
  118. static void t1_set_rxmode(struct net_device *dev)
  119. {
  120. struct adapter *adapter = dev->priv;
  121. struct cmac *mac = adapter->port[dev->if_port].mac;
  122. struct t1_rx_mode rm;
  123. rm.dev = dev;
  124. rm.idx = 0;
  125. rm.list = dev->mc_list;
  126. mac->ops->set_rx_mode(mac, &rm);
  127. }
  128. static void link_report(struct port_info *p)
  129. {
  130. if (!netif_carrier_ok(p->dev))
  131. printk(KERN_INFO "%s: link down\n", p->dev->name);
  132. else {
  133. const char *s = "10Mbps";
  134. switch (p->link_config.speed) {
  135. case SPEED_10000: s = "10Gbps"; break;
  136. case SPEED_1000: s = "1000Mbps"; break;
  137. case SPEED_100: s = "100Mbps"; break;
  138. }
  139. printk(KERN_INFO "%s: link up, %s, %s-duplex\n",
  140. p->dev->name, s,
  141. p->link_config.duplex == DUPLEX_FULL ? "full" : "half");
  142. }
  143. }
  144. void t1_link_changed(struct adapter *adapter, int port_id, int link_stat,
  145. int speed, int duplex, int pause)
  146. {
  147. struct port_info *p = &adapter->port[port_id];
  148. if (link_stat != netif_carrier_ok(p->dev)) {
  149. if (link_stat)
  150. netif_carrier_on(p->dev);
  151. else
  152. netif_carrier_off(p->dev);
  153. link_report(p);
  154. }
  155. }
  156. static void link_start(struct port_info *p)
  157. {
  158. struct cmac *mac = p->mac;
  159. mac->ops->reset(mac);
  160. if (mac->ops->macaddress_set)
  161. mac->ops->macaddress_set(mac, p->dev->dev_addr);
  162. t1_set_rxmode(p->dev);
  163. t1_link_start(p->phy, mac, &p->link_config);
  164. mac->ops->enable(mac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
  165. }
  166. static void enable_hw_csum(struct adapter *adapter)
  167. {
  168. if (adapter->flags & TSO_CAPABLE)
  169. t1_tp_set_ip_checksum_offload(adapter, 1); /* for TSO only */
  170. t1_tp_set_tcp_checksum_offload(adapter, 1);
  171. }
  172. /*
  173. * Things to do upon first use of a card.
  174. * This must run with the rtnl lock held.
  175. */
  176. static int cxgb_up(struct adapter *adapter)
  177. {
  178. int err = 0;
  179. if (!(adapter->flags & FULL_INIT_DONE)) {
  180. err = t1_init_hw_modules(adapter);
  181. if (err)
  182. goto out_err;
  183. enable_hw_csum(adapter);
  184. adapter->flags |= FULL_INIT_DONE;
  185. }
  186. t1_interrupts_clear(adapter);
  187. if ((err = request_irq(adapter->pdev->irq,
  188. t1_select_intr_handler(adapter), IRQF_SHARED,
  189. adapter->name, adapter))) {
  190. goto out_err;
  191. }
  192. t1_sge_start(adapter->sge);
  193. t1_interrupts_enable(adapter);
  194. out_err:
  195. return err;
  196. }
  197. /*
  198. * Release resources when all the ports have been stopped.
  199. */
  200. static void cxgb_down(struct adapter *adapter)
  201. {
  202. t1_sge_stop(adapter->sge);
  203. t1_interrupts_disable(adapter);
  204. free_irq(adapter->pdev->irq, adapter);
  205. }
  206. static int cxgb_open(struct net_device *dev)
  207. {
  208. int err;
  209. struct adapter *adapter = dev->priv;
  210. int other_ports = adapter->open_device_map & PORT_MASK;
  211. if (!adapter->open_device_map && (err = cxgb_up(adapter)) < 0)
  212. return err;
  213. __set_bit(dev->if_port, &adapter->open_device_map);
  214. link_start(&adapter->port[dev->if_port]);
  215. netif_start_queue(dev);
  216. if (!other_ports && adapter->params.stats_update_period)
  217. schedule_mac_stats_update(adapter,
  218. adapter->params.stats_update_period);
  219. return 0;
  220. }
  221. static int cxgb_close(struct net_device *dev)
  222. {
  223. struct adapter *adapter = dev->priv;
  224. struct port_info *p = &adapter->port[dev->if_port];
  225. struct cmac *mac = p->mac;
  226. netif_stop_queue(dev);
  227. mac->ops->disable(mac, MAC_DIRECTION_TX | MAC_DIRECTION_RX);
  228. netif_carrier_off(dev);
  229. clear_bit(dev->if_port, &adapter->open_device_map);
  230. if (adapter->params.stats_update_period &&
  231. !(adapter->open_device_map & PORT_MASK)) {
  232. /* Stop statistics accumulation. */
  233. smp_mb__after_clear_bit();
  234. spin_lock(&adapter->work_lock); /* sync with update task */
  235. spin_unlock(&adapter->work_lock);
  236. cancel_mac_stats_update(adapter);
  237. }
  238. if (!adapter->open_device_map)
  239. cxgb_down(adapter);
  240. return 0;
  241. }
  242. static struct net_device_stats *t1_get_stats(struct net_device *dev)
  243. {
  244. struct adapter *adapter = dev->priv;
  245. struct port_info *p = &adapter->port[dev->if_port];
  246. struct net_device_stats *ns = &p->netstats;
  247. const struct cmac_statistics *pstats;
  248. /* Do a full update of the MAC stats */
  249. pstats = p->mac->ops->statistics_update(p->mac,
  250. MAC_STATS_UPDATE_FULL);
  251. ns->tx_packets = pstats->TxUnicastFramesOK +
  252. pstats->TxMulticastFramesOK + pstats->TxBroadcastFramesOK;
  253. ns->rx_packets = pstats->RxUnicastFramesOK +
  254. pstats->RxMulticastFramesOK + pstats->RxBroadcastFramesOK;
  255. ns->tx_bytes = pstats->TxOctetsOK;
  256. ns->rx_bytes = pstats->RxOctetsOK;
  257. ns->tx_errors = pstats->TxLateCollisions + pstats->TxLengthErrors +
  258. pstats->TxUnderrun + pstats->TxFramesAbortedDueToXSCollisions;
  259. ns->rx_errors = pstats->RxDataErrors + pstats->RxJabberErrors +
  260. pstats->RxFCSErrors + pstats->RxAlignErrors +
  261. pstats->RxSequenceErrors + pstats->RxFrameTooLongErrors +
  262. pstats->RxSymbolErrors + pstats->RxRuntErrors;
  263. ns->multicast = pstats->RxMulticastFramesOK;
  264. ns->collisions = pstats->TxTotalCollisions;
  265. /* detailed rx_errors */
  266. ns->rx_length_errors = pstats->RxFrameTooLongErrors +
  267. pstats->RxJabberErrors;
  268. ns->rx_over_errors = 0;
  269. ns->rx_crc_errors = pstats->RxFCSErrors;
  270. ns->rx_frame_errors = pstats->RxAlignErrors;
  271. ns->rx_fifo_errors = 0;
  272. ns->rx_missed_errors = 0;
  273. /* detailed tx_errors */
  274. ns->tx_aborted_errors = pstats->TxFramesAbortedDueToXSCollisions;
  275. ns->tx_carrier_errors = 0;
  276. ns->tx_fifo_errors = pstats->TxUnderrun;
  277. ns->tx_heartbeat_errors = 0;
  278. ns->tx_window_errors = pstats->TxLateCollisions;
  279. return ns;
  280. }
  281. static u32 get_msglevel(struct net_device *dev)
  282. {
  283. struct adapter *adapter = dev->priv;
  284. return adapter->msg_enable;
  285. }
  286. static void set_msglevel(struct net_device *dev, u32 val)
  287. {
  288. struct adapter *adapter = dev->priv;
  289. adapter->msg_enable = val;
  290. }
  291. static char stats_strings[][ETH_GSTRING_LEN] = {
  292. "TxOctetsOK",
  293. "TxOctetsBad",
  294. "TxUnicastFramesOK",
  295. "TxMulticastFramesOK",
  296. "TxBroadcastFramesOK",
  297. "TxPauseFrames",
  298. "TxFramesWithDeferredXmissions",
  299. "TxLateCollisions",
  300. "TxTotalCollisions",
  301. "TxFramesAbortedDueToXSCollisions",
  302. "TxUnderrun",
  303. "TxLengthErrors",
  304. "TxInternalMACXmitError",
  305. "TxFramesWithExcessiveDeferral",
  306. "TxFCSErrors",
  307. "RxOctetsOK",
  308. "RxOctetsBad",
  309. "RxUnicastFramesOK",
  310. "RxMulticastFramesOK",
  311. "RxBroadcastFramesOK",
  312. "RxPauseFrames",
  313. "RxFCSErrors",
  314. "RxAlignErrors",
  315. "RxSymbolErrors",
  316. "RxDataErrors",
  317. "RxSequenceErrors",
  318. "RxRuntErrors",
  319. "RxJabberErrors",
  320. "RxInternalMACRcvError",
  321. "RxInRangeLengthErrors",
  322. "RxOutOfRangeLengthField",
  323. "RxFrameTooLongErrors",
  324. "TSO",
  325. "VLANextractions",
  326. "VLANinsertions",
  327. "RxCsumGood",
  328. "TxCsumOffload",
  329. "RxDrops"
  330. "respQ_empty",
  331. "respQ_overflow",
  332. "freelistQ_empty",
  333. "pkt_too_big",
  334. "pkt_mismatch",
  335. "cmdQ_full0",
  336. "cmdQ_full1",
  337. "tx_ipfrags",
  338. "tx_reg_pkts",
  339. "tx_lso_pkts",
  340. "tx_do_cksum",
  341. "espi_DIP2ParityErr",
  342. "espi_DIP4Err",
  343. "espi_RxDrops",
  344. "espi_TxDrops",
  345. "espi_RxOvfl",
  346. "espi_ParityErr"
  347. };
  348. #define T2_REGMAP_SIZE (3 * 1024)
  349. static int get_regs_len(struct net_device *dev)
  350. {
  351. return T2_REGMAP_SIZE;
  352. }
  353. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  354. {
  355. struct adapter *adapter = dev->priv;
  356. strcpy(info->driver, DRV_NAME);
  357. strcpy(info->version, DRV_VERSION);
  358. strcpy(info->fw_version, "N/A");
  359. strcpy(info->bus_info, pci_name(adapter->pdev));
  360. }
  361. static int get_stats_count(struct net_device *dev)
  362. {
  363. return ARRAY_SIZE(stats_strings);
  364. }
  365. static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
  366. {
  367. if (stringset == ETH_SS_STATS)
  368. memcpy(data, stats_strings, sizeof(stats_strings));
  369. }
  370. static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
  371. u64 *data)
  372. {
  373. struct adapter *adapter = dev->priv;
  374. struct cmac *mac = adapter->port[dev->if_port].mac;
  375. const struct cmac_statistics *s;
  376. const struct sge_port_stats *ss;
  377. const struct sge_intr_counts *t;
  378. s = mac->ops->statistics_update(mac, MAC_STATS_UPDATE_FULL);
  379. ss = t1_sge_get_port_stats(adapter->sge, dev->if_port);
  380. t = t1_sge_get_intr_counts(adapter->sge);
  381. *data++ = s->TxOctetsOK;
  382. *data++ = s->TxOctetsBad;
  383. *data++ = s->TxUnicastFramesOK;
  384. *data++ = s->TxMulticastFramesOK;
  385. *data++ = s->TxBroadcastFramesOK;
  386. *data++ = s->TxPauseFrames;
  387. *data++ = s->TxFramesWithDeferredXmissions;
  388. *data++ = s->TxLateCollisions;
  389. *data++ = s->TxTotalCollisions;
  390. *data++ = s->TxFramesAbortedDueToXSCollisions;
  391. *data++ = s->TxUnderrun;
  392. *data++ = s->TxLengthErrors;
  393. *data++ = s->TxInternalMACXmitError;
  394. *data++ = s->TxFramesWithExcessiveDeferral;
  395. *data++ = s->TxFCSErrors;
  396. *data++ = s->RxOctetsOK;
  397. *data++ = s->RxOctetsBad;
  398. *data++ = s->RxUnicastFramesOK;
  399. *data++ = s->RxMulticastFramesOK;
  400. *data++ = s->RxBroadcastFramesOK;
  401. *data++ = s->RxPauseFrames;
  402. *data++ = s->RxFCSErrors;
  403. *data++ = s->RxAlignErrors;
  404. *data++ = s->RxSymbolErrors;
  405. *data++ = s->RxDataErrors;
  406. *data++ = s->RxSequenceErrors;
  407. *data++ = s->RxRuntErrors;
  408. *data++ = s->RxJabberErrors;
  409. *data++ = s->RxInternalMACRcvError;
  410. *data++ = s->RxInRangeLengthErrors;
  411. *data++ = s->RxOutOfRangeLengthField;
  412. *data++ = s->RxFrameTooLongErrors;
  413. *data++ = ss->tso;
  414. *data++ = ss->vlan_xtract;
  415. *data++ = ss->vlan_insert;
  416. *data++ = ss->rx_cso_good;
  417. *data++ = ss->tx_cso;
  418. *data++ = ss->rx_drops;
  419. *data++ = (u64)t->respQ_empty;
  420. *data++ = (u64)t->respQ_overflow;
  421. *data++ = (u64)t->freelistQ_empty;
  422. *data++ = (u64)t->pkt_too_big;
  423. *data++ = (u64)t->pkt_mismatch;
  424. *data++ = (u64)t->cmdQ_full[0];
  425. *data++ = (u64)t->cmdQ_full[1];
  426. *data++ = (u64)t->tx_ipfrags;
  427. *data++ = (u64)t->tx_reg_pkts;
  428. *data++ = (u64)t->tx_lso_pkts;
  429. *data++ = (u64)t->tx_do_cksum;
  430. }
  431. static inline void reg_block_dump(struct adapter *ap, void *buf,
  432. unsigned int start, unsigned int end)
  433. {
  434. u32 *p = buf + start;
  435. for ( ; start <= end; start += sizeof(u32))
  436. *p++ = readl(ap->regs + start);
  437. }
  438. static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
  439. void *buf)
  440. {
  441. struct adapter *ap = dev->priv;
  442. /*
  443. * Version scheme: bits 0..9: chip version, bits 10..15: chip revision
  444. */
  445. regs->version = 2;
  446. memset(buf, 0, T2_REGMAP_SIZE);
  447. reg_block_dump(ap, buf, 0, A_SG_RESPACCUTIMER);
  448. }
  449. static int get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  450. {
  451. struct adapter *adapter = dev->priv;
  452. struct port_info *p = &adapter->port[dev->if_port];
  453. cmd->supported = p->link_config.supported;
  454. cmd->advertising = p->link_config.advertising;
  455. if (netif_carrier_ok(dev)) {
  456. cmd->speed = p->link_config.speed;
  457. cmd->duplex = p->link_config.duplex;
  458. } else {
  459. cmd->speed = -1;
  460. cmd->duplex = -1;
  461. }
  462. cmd->port = (cmd->supported & SUPPORTED_TP) ? PORT_TP : PORT_FIBRE;
  463. cmd->phy_address = p->phy->addr;
  464. cmd->transceiver = XCVR_EXTERNAL;
  465. cmd->autoneg = p->link_config.autoneg;
  466. cmd->maxtxpkt = 0;
  467. cmd->maxrxpkt = 0;
  468. return 0;
  469. }
  470. static int speed_duplex_to_caps(int speed, int duplex)
  471. {
  472. int cap = 0;
  473. switch (speed) {
  474. case SPEED_10:
  475. if (duplex == DUPLEX_FULL)
  476. cap = SUPPORTED_10baseT_Full;
  477. else
  478. cap = SUPPORTED_10baseT_Half;
  479. break;
  480. case SPEED_100:
  481. if (duplex == DUPLEX_FULL)
  482. cap = SUPPORTED_100baseT_Full;
  483. else
  484. cap = SUPPORTED_100baseT_Half;
  485. break;
  486. case SPEED_1000:
  487. if (duplex == DUPLEX_FULL)
  488. cap = SUPPORTED_1000baseT_Full;
  489. else
  490. cap = SUPPORTED_1000baseT_Half;
  491. break;
  492. case SPEED_10000:
  493. if (duplex == DUPLEX_FULL)
  494. cap = SUPPORTED_10000baseT_Full;
  495. }
  496. return cap;
  497. }
  498. #define ADVERTISED_MASK (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  499. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  500. ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | \
  501. ADVERTISED_10000baseT_Full)
  502. static int set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  503. {
  504. struct adapter *adapter = dev->priv;
  505. struct port_info *p = &adapter->port[dev->if_port];
  506. struct link_config *lc = &p->link_config;
  507. if (!(lc->supported & SUPPORTED_Autoneg))
  508. return -EOPNOTSUPP; /* can't change speed/duplex */
  509. if (cmd->autoneg == AUTONEG_DISABLE) {
  510. int cap = speed_duplex_to_caps(cmd->speed, cmd->duplex);
  511. if (!(lc->supported & cap) || cmd->speed == SPEED_1000)
  512. return -EINVAL;
  513. lc->requested_speed = cmd->speed;
  514. lc->requested_duplex = cmd->duplex;
  515. lc->advertising = 0;
  516. } else {
  517. cmd->advertising &= ADVERTISED_MASK;
  518. if (cmd->advertising & (cmd->advertising - 1))
  519. cmd->advertising = lc->supported;
  520. cmd->advertising &= lc->supported;
  521. if (!cmd->advertising)
  522. return -EINVAL;
  523. lc->requested_speed = SPEED_INVALID;
  524. lc->requested_duplex = DUPLEX_INVALID;
  525. lc->advertising = cmd->advertising | ADVERTISED_Autoneg;
  526. }
  527. lc->autoneg = cmd->autoneg;
  528. if (netif_running(dev))
  529. t1_link_start(p->phy, p->mac, lc);
  530. return 0;
  531. }
  532. static void get_pauseparam(struct net_device *dev,
  533. struct ethtool_pauseparam *epause)
  534. {
  535. struct adapter *adapter = dev->priv;
  536. struct port_info *p = &adapter->port[dev->if_port];
  537. epause->autoneg = (p->link_config.requested_fc & PAUSE_AUTONEG) != 0;
  538. epause->rx_pause = (p->link_config.fc & PAUSE_RX) != 0;
  539. epause->tx_pause = (p->link_config.fc & PAUSE_TX) != 0;
  540. }
  541. static int set_pauseparam(struct net_device *dev,
  542. struct ethtool_pauseparam *epause)
  543. {
  544. struct adapter *adapter = dev->priv;
  545. struct port_info *p = &adapter->port[dev->if_port];
  546. struct link_config *lc = &p->link_config;
  547. if (epause->autoneg == AUTONEG_DISABLE)
  548. lc->requested_fc = 0;
  549. else if (lc->supported & SUPPORTED_Autoneg)
  550. lc->requested_fc = PAUSE_AUTONEG;
  551. else
  552. return -EINVAL;
  553. if (epause->rx_pause)
  554. lc->requested_fc |= PAUSE_RX;
  555. if (epause->tx_pause)
  556. lc->requested_fc |= PAUSE_TX;
  557. if (lc->autoneg == AUTONEG_ENABLE) {
  558. if (netif_running(dev))
  559. t1_link_start(p->phy, p->mac, lc);
  560. } else {
  561. lc->fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  562. if (netif_running(dev))
  563. p->mac->ops->set_speed_duplex_fc(p->mac, -1, -1,
  564. lc->fc);
  565. }
  566. return 0;
  567. }
  568. static u32 get_rx_csum(struct net_device *dev)
  569. {
  570. struct adapter *adapter = dev->priv;
  571. return (adapter->flags & RX_CSUM_ENABLED) != 0;
  572. }
  573. static int set_rx_csum(struct net_device *dev, u32 data)
  574. {
  575. struct adapter *adapter = dev->priv;
  576. if (data)
  577. adapter->flags |= RX_CSUM_ENABLED;
  578. else
  579. adapter->flags &= ~RX_CSUM_ENABLED;
  580. return 0;
  581. }
  582. static int set_tso(struct net_device *dev, u32 value)
  583. {
  584. struct adapter *adapter = dev->priv;
  585. if (!(adapter->flags & TSO_CAPABLE))
  586. return value ? -EOPNOTSUPP : 0;
  587. return ethtool_op_set_tso(dev, value);
  588. }
  589. static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  590. {
  591. struct adapter *adapter = dev->priv;
  592. int jumbo_fl = t1_is_T1B(adapter) ? 1 : 0;
  593. e->rx_max_pending = MAX_RX_BUFFERS;
  594. e->rx_mini_max_pending = 0;
  595. e->rx_jumbo_max_pending = MAX_RX_JUMBO_BUFFERS;
  596. e->tx_max_pending = MAX_CMDQ_ENTRIES;
  597. e->rx_pending = adapter->params.sge.freelQ_size[!jumbo_fl];
  598. e->rx_mini_pending = 0;
  599. e->rx_jumbo_pending = adapter->params.sge.freelQ_size[jumbo_fl];
  600. e->tx_pending = adapter->params.sge.cmdQ_size[0];
  601. }
  602. static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  603. {
  604. struct adapter *adapter = dev->priv;
  605. int jumbo_fl = t1_is_T1B(adapter) ? 1 : 0;
  606. if (e->rx_pending > MAX_RX_BUFFERS || e->rx_mini_pending ||
  607. e->rx_jumbo_pending > MAX_RX_JUMBO_BUFFERS ||
  608. e->tx_pending > MAX_CMDQ_ENTRIES ||
  609. e->rx_pending < MIN_FL_ENTRIES ||
  610. e->rx_jumbo_pending < MIN_FL_ENTRIES ||
  611. e->tx_pending < (adapter->params.nports + 1) * (MAX_SKB_FRAGS + 1))
  612. return -EINVAL;
  613. if (adapter->flags & FULL_INIT_DONE)
  614. return -EBUSY;
  615. adapter->params.sge.freelQ_size[!jumbo_fl] = e->rx_pending;
  616. adapter->params.sge.freelQ_size[jumbo_fl] = e->rx_jumbo_pending;
  617. adapter->params.sge.cmdQ_size[0] = e->tx_pending;
  618. adapter->params.sge.cmdQ_size[1] = e->tx_pending > MAX_CMDQ1_ENTRIES ?
  619. MAX_CMDQ1_ENTRIES : e->tx_pending;
  620. return 0;
  621. }
  622. static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  623. {
  624. struct adapter *adapter = dev->priv;
  625. /*
  626. * If RX coalescing is requested we use NAPI, otherwise interrupts.
  627. * This choice can be made only when all ports and the TOE are off.
  628. */
  629. if (adapter->open_device_map == 0)
  630. adapter->params.sge.polling = c->use_adaptive_rx_coalesce;
  631. if (adapter->params.sge.polling) {
  632. adapter->params.sge.rx_coalesce_usecs = 0;
  633. } else {
  634. adapter->params.sge.rx_coalesce_usecs = c->rx_coalesce_usecs;
  635. }
  636. adapter->params.sge.coalesce_enable = c->use_adaptive_rx_coalesce;
  637. adapter->params.sge.sample_interval_usecs = c->rate_sample_interval;
  638. t1_sge_set_coalesce_params(adapter->sge, &adapter->params.sge);
  639. return 0;
  640. }
  641. static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  642. {
  643. struct adapter *adapter = dev->priv;
  644. c->rx_coalesce_usecs = adapter->params.sge.rx_coalesce_usecs;
  645. c->rate_sample_interval = adapter->params.sge.sample_interval_usecs;
  646. c->use_adaptive_rx_coalesce = adapter->params.sge.coalesce_enable;
  647. return 0;
  648. }
  649. static int get_eeprom_len(struct net_device *dev)
  650. {
  651. return EEPROM_SIZE;
  652. }
  653. #define EEPROM_MAGIC(ap) \
  654. (PCI_VENDOR_ID_CHELSIO | ((ap)->params.chip_version << 16))
  655. static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
  656. u8 *data)
  657. {
  658. int i;
  659. u8 buf[EEPROM_SIZE] __attribute__((aligned(4)));
  660. struct adapter *adapter = dev->priv;
  661. e->magic = EEPROM_MAGIC(adapter);
  662. for (i = e->offset & ~3; i < e->offset + e->len; i += sizeof(u32))
  663. t1_seeprom_read(adapter, i, (u32 *)&buf[i]);
  664. memcpy(data, buf + e->offset, e->len);
  665. return 0;
  666. }
  667. static const struct ethtool_ops t1_ethtool_ops = {
  668. .get_settings = get_settings,
  669. .set_settings = set_settings,
  670. .get_drvinfo = get_drvinfo,
  671. .get_msglevel = get_msglevel,
  672. .set_msglevel = set_msglevel,
  673. .get_ringparam = get_sge_param,
  674. .set_ringparam = set_sge_param,
  675. .get_coalesce = get_coalesce,
  676. .set_coalesce = set_coalesce,
  677. .get_eeprom_len = get_eeprom_len,
  678. .get_eeprom = get_eeprom,
  679. .get_pauseparam = get_pauseparam,
  680. .set_pauseparam = set_pauseparam,
  681. .get_rx_csum = get_rx_csum,
  682. .set_rx_csum = set_rx_csum,
  683. .get_tx_csum = ethtool_op_get_tx_csum,
  684. .set_tx_csum = ethtool_op_set_tx_csum,
  685. .get_sg = ethtool_op_get_sg,
  686. .set_sg = ethtool_op_set_sg,
  687. .get_link = ethtool_op_get_link,
  688. .get_strings = get_strings,
  689. .get_stats_count = get_stats_count,
  690. .get_ethtool_stats = get_stats,
  691. .get_regs_len = get_regs_len,
  692. .get_regs = get_regs,
  693. .get_tso = ethtool_op_get_tso,
  694. .set_tso = set_tso,
  695. };
  696. static void cxgb_proc_cleanup(struct adapter *adapter,
  697. struct proc_dir_entry *dir)
  698. {
  699. const char *name;
  700. name = adapter->name;
  701. remove_proc_entry(name, dir);
  702. }
  703. //#define chtoe_setup_toedev(adapter) NULL
  704. #define update_mtu_tab(adapter)
  705. #define write_smt_entry(adapter, idx)
  706. static int t1_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  707. {
  708. struct adapter *adapter = dev->priv;
  709. struct mii_ioctl_data *data = if_mii(req);
  710. switch (cmd) {
  711. case SIOCGMIIPHY:
  712. data->phy_id = adapter->port[dev->if_port].phy->addr;
  713. /* FALLTHRU */
  714. case SIOCGMIIREG: {
  715. struct cphy *phy = adapter->port[dev->if_port].phy;
  716. u32 val;
  717. if (!phy->mdio_read)
  718. return -EOPNOTSUPP;
  719. phy->mdio_read(adapter, data->phy_id, 0, data->reg_num & 0x1f,
  720. &val);
  721. data->val_out = val;
  722. break;
  723. }
  724. case SIOCSMIIREG: {
  725. struct cphy *phy = adapter->port[dev->if_port].phy;
  726. if (!capable(CAP_NET_ADMIN))
  727. return -EPERM;
  728. if (!phy->mdio_write)
  729. return -EOPNOTSUPP;
  730. phy->mdio_write(adapter, data->phy_id, 0, data->reg_num & 0x1f,
  731. data->val_in);
  732. break;
  733. }
  734. default:
  735. return -EOPNOTSUPP;
  736. }
  737. return 0;
  738. }
  739. static int t1_change_mtu(struct net_device *dev, int new_mtu)
  740. {
  741. int ret;
  742. struct adapter *adapter = dev->priv;
  743. struct cmac *mac = adapter->port[dev->if_port].mac;
  744. if (!mac->ops->set_mtu)
  745. return -EOPNOTSUPP;
  746. if (new_mtu < 68)
  747. return -EINVAL;
  748. if ((ret = mac->ops->set_mtu(mac, new_mtu)))
  749. return ret;
  750. dev->mtu = new_mtu;
  751. return 0;
  752. }
  753. static int t1_set_mac_addr(struct net_device *dev, void *p)
  754. {
  755. struct adapter *adapter = dev->priv;
  756. struct cmac *mac = adapter->port[dev->if_port].mac;
  757. struct sockaddr *addr = p;
  758. if (!mac->ops->macaddress_set)
  759. return -EOPNOTSUPP;
  760. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  761. mac->ops->macaddress_set(mac, dev->dev_addr);
  762. return 0;
  763. }
  764. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  765. static void vlan_rx_register(struct net_device *dev,
  766. struct vlan_group *grp)
  767. {
  768. struct adapter *adapter = dev->priv;
  769. spin_lock_irq(&adapter->async_lock);
  770. adapter->vlan_grp = grp;
  771. t1_set_vlan_accel(adapter, grp != NULL);
  772. spin_unlock_irq(&adapter->async_lock);
  773. }
  774. static void vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  775. {
  776. struct adapter *adapter = dev->priv;
  777. spin_lock_irq(&adapter->async_lock);
  778. if (adapter->vlan_grp)
  779. adapter->vlan_grp->vlan_devices[vid] = NULL;
  780. spin_unlock_irq(&adapter->async_lock);
  781. }
  782. #endif
  783. #ifdef CONFIG_NET_POLL_CONTROLLER
  784. static void t1_netpoll(struct net_device *dev)
  785. {
  786. unsigned long flags;
  787. struct adapter *adapter = dev->priv;
  788. local_irq_save(flags);
  789. t1_select_intr_handler(adapter)(adapter->pdev->irq, adapter);
  790. local_irq_restore(flags);
  791. }
  792. #endif
  793. /*
  794. * Periodic accumulation of MAC statistics. This is used only if the MAC
  795. * does not have any other way to prevent stats counter overflow.
  796. */
  797. static void mac_stats_task(void *data)
  798. {
  799. int i;
  800. struct adapter *adapter = data;
  801. for_each_port(adapter, i) {
  802. struct port_info *p = &adapter->port[i];
  803. if (netif_running(p->dev))
  804. p->mac->ops->statistics_update(p->mac,
  805. MAC_STATS_UPDATE_FAST);
  806. }
  807. /* Schedule the next statistics update if any port is active. */
  808. spin_lock(&adapter->work_lock);
  809. if (adapter->open_device_map & PORT_MASK)
  810. schedule_mac_stats_update(adapter,
  811. adapter->params.stats_update_period);
  812. spin_unlock(&adapter->work_lock);
  813. }
  814. /*
  815. * Processes elmer0 external interrupts in process context.
  816. */
  817. static void ext_intr_task(void *data)
  818. {
  819. struct adapter *adapter = data;
  820. elmer0_ext_intr_handler(adapter);
  821. /* Now reenable external interrupts */
  822. spin_lock_irq(&adapter->async_lock);
  823. adapter->slow_intr_mask |= F_PL_INTR_EXT;
  824. writel(F_PL_INTR_EXT, adapter->regs + A_PL_CAUSE);
  825. writel(adapter->slow_intr_mask | F_PL_INTR_SGE_DATA,
  826. adapter->regs + A_PL_ENABLE);
  827. spin_unlock_irq(&adapter->async_lock);
  828. }
  829. /*
  830. * Interrupt-context handler for elmer0 external interrupts.
  831. */
  832. void t1_elmer0_ext_intr(struct adapter *adapter)
  833. {
  834. /*
  835. * Schedule a task to handle external interrupts as we require
  836. * a process context. We disable EXT interrupts in the interim
  837. * and let the task reenable them when it's done.
  838. */
  839. adapter->slow_intr_mask &= ~F_PL_INTR_EXT;
  840. writel(adapter->slow_intr_mask | F_PL_INTR_SGE_DATA,
  841. adapter->regs + A_PL_ENABLE);
  842. schedule_work(&adapter->ext_intr_handler_task);
  843. }
  844. void t1_fatal_err(struct adapter *adapter)
  845. {
  846. if (adapter->flags & FULL_INIT_DONE) {
  847. t1_sge_stop(adapter->sge);
  848. t1_interrupts_disable(adapter);
  849. }
  850. CH_ALERT("%s: encountered fatal error, operation suspended\n",
  851. adapter->name);
  852. }
  853. static int __devinit init_one(struct pci_dev *pdev,
  854. const struct pci_device_id *ent)
  855. {
  856. static int version_printed;
  857. int i, err, pci_using_dac = 0;
  858. unsigned long mmio_start, mmio_len;
  859. const struct board_info *bi;
  860. struct adapter *adapter = NULL;
  861. struct port_info *pi;
  862. if (!version_printed) {
  863. printk(KERN_INFO "%s - version %s\n", DRV_DESCRIPTION,
  864. DRV_VERSION);
  865. ++version_printed;
  866. }
  867. err = pci_enable_device(pdev);
  868. if (err)
  869. return err;
  870. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  871. CH_ERR("%s: cannot find PCI device memory base address\n",
  872. pci_name(pdev));
  873. err = -ENODEV;
  874. goto out_disable_pdev;
  875. }
  876. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  877. pci_using_dac = 1;
  878. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
  879. CH_ERR("%s: unable to obtain 64-bit DMA for"
  880. "consistent allocations\n", pci_name(pdev));
  881. err = -ENODEV;
  882. goto out_disable_pdev;
  883. }
  884. } else if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) != 0) {
  885. CH_ERR("%s: no usable DMA configuration\n", pci_name(pdev));
  886. goto out_disable_pdev;
  887. }
  888. err = pci_request_regions(pdev, DRV_NAME);
  889. if (err) {
  890. CH_ERR("%s: cannot obtain PCI resources\n", pci_name(pdev));
  891. goto out_disable_pdev;
  892. }
  893. pci_set_master(pdev);
  894. mmio_start = pci_resource_start(pdev, 0);
  895. mmio_len = pci_resource_len(pdev, 0);
  896. bi = t1_get_board_info(ent->driver_data);
  897. for (i = 0; i < bi->port_number; ++i) {
  898. struct net_device *netdev;
  899. netdev = alloc_etherdev(adapter ? 0 : sizeof(*adapter));
  900. if (!netdev) {
  901. err = -ENOMEM;
  902. goto out_free_dev;
  903. }
  904. SET_MODULE_OWNER(netdev);
  905. SET_NETDEV_DEV(netdev, &pdev->dev);
  906. if (!adapter) {
  907. adapter = netdev->priv;
  908. adapter->pdev = pdev;
  909. adapter->port[0].dev = netdev; /* so we don't leak it */
  910. adapter->regs = ioremap(mmio_start, mmio_len);
  911. if (!adapter->regs) {
  912. CH_ERR("%s: cannot map device registers\n",
  913. pci_name(pdev));
  914. err = -ENOMEM;
  915. goto out_free_dev;
  916. }
  917. if (t1_get_board_rev(adapter, bi, &adapter->params)) {
  918. err = -ENODEV; /* Can't handle this chip rev */
  919. goto out_free_dev;
  920. }
  921. adapter->name = pci_name(pdev);
  922. adapter->msg_enable = dflt_msg_enable;
  923. adapter->mmio_len = mmio_len;
  924. init_MUTEX(&adapter->mib_mutex);
  925. spin_lock_init(&adapter->tpi_lock);
  926. spin_lock_init(&adapter->work_lock);
  927. spin_lock_init(&adapter->async_lock);
  928. INIT_WORK(&adapter->ext_intr_handler_task,
  929. ext_intr_task, adapter);
  930. INIT_WORK(&adapter->stats_update_task, mac_stats_task,
  931. adapter);
  932. #ifdef work_struct
  933. init_timer(&adapter->stats_update_timer);
  934. adapter->stats_update_timer.function = mac_stats_timer;
  935. adapter->stats_update_timer.data =
  936. (unsigned long)adapter;
  937. #endif
  938. pci_set_drvdata(pdev, netdev);
  939. }
  940. pi = &adapter->port[i];
  941. pi->dev = netdev;
  942. netif_carrier_off(netdev);
  943. netdev->irq = pdev->irq;
  944. netdev->if_port = i;
  945. netdev->mem_start = mmio_start;
  946. netdev->mem_end = mmio_start + mmio_len - 1;
  947. netdev->priv = adapter;
  948. netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  949. netdev->features |= NETIF_F_LLTX;
  950. adapter->flags |= RX_CSUM_ENABLED | TCP_CSUM_CAPABLE;
  951. if (pci_using_dac)
  952. netdev->features |= NETIF_F_HIGHDMA;
  953. if (vlan_tso_capable(adapter)) {
  954. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  955. adapter->flags |= VLAN_ACCEL_CAPABLE;
  956. netdev->features |=
  957. NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  958. netdev->vlan_rx_register = vlan_rx_register;
  959. netdev->vlan_rx_kill_vid = vlan_rx_kill_vid;
  960. #endif
  961. adapter->flags |= TSO_CAPABLE;
  962. netdev->features |= NETIF_F_TSO;
  963. }
  964. netdev->open = cxgb_open;
  965. netdev->stop = cxgb_close;
  966. netdev->hard_start_xmit = t1_start_xmit;
  967. netdev->hard_header_len += (adapter->flags & TSO_CAPABLE) ?
  968. sizeof(struct cpl_tx_pkt_lso) :
  969. sizeof(struct cpl_tx_pkt);
  970. netdev->get_stats = t1_get_stats;
  971. netdev->set_multicast_list = t1_set_rxmode;
  972. netdev->do_ioctl = t1_ioctl;
  973. netdev->change_mtu = t1_change_mtu;
  974. netdev->set_mac_address = t1_set_mac_addr;
  975. #ifdef CONFIG_NET_POLL_CONTROLLER
  976. netdev->poll_controller = t1_netpoll;
  977. #endif
  978. netdev->weight = 64;
  979. SET_ETHTOOL_OPS(netdev, &t1_ethtool_ops);
  980. }
  981. if (t1_init_sw_modules(adapter, bi) < 0) {
  982. err = -ENODEV;
  983. goto out_free_dev;
  984. }
  985. /*
  986. * The card is now ready to go. If any errors occur during device
  987. * registration we do not fail the whole card but rather proceed only
  988. * with the ports we manage to register successfully. However we must
  989. * register at least one net device.
  990. */
  991. for (i = 0; i < bi->port_number; ++i) {
  992. err = register_netdev(adapter->port[i].dev);
  993. if (err)
  994. CH_WARN("%s: cannot register net device %s, skipping\n",
  995. pci_name(pdev), adapter->port[i].dev->name);
  996. else {
  997. /*
  998. * Change the name we use for messages to the name of
  999. * the first successfully registered interface.
  1000. */
  1001. if (!adapter->registered_device_map)
  1002. adapter->name = adapter->port[i].dev->name;
  1003. __set_bit(i, &adapter->registered_device_map);
  1004. }
  1005. }
  1006. if (!adapter->registered_device_map) {
  1007. CH_ERR("%s: could not register any net devices\n",
  1008. pci_name(pdev));
  1009. goto out_release_adapter_res;
  1010. }
  1011. printk(KERN_INFO "%s: %s (rev %d), %s %dMHz/%d-bit\n", adapter->name,
  1012. bi->desc, adapter->params.chip_revision,
  1013. adapter->params.pci.is_pcix ? "PCIX" : "PCI",
  1014. adapter->params.pci.speed, adapter->params.pci.width);
  1015. return 0;
  1016. out_release_adapter_res:
  1017. t1_free_sw_modules(adapter);
  1018. out_free_dev:
  1019. if (adapter) {
  1020. if (adapter->regs) iounmap(adapter->regs);
  1021. for (i = bi->port_number - 1; i >= 0; --i)
  1022. if (adapter->port[i].dev) {
  1023. cxgb_proc_cleanup(adapter, proc_root_driver);
  1024. kfree(adapter->port[i].dev);
  1025. }
  1026. }
  1027. pci_release_regions(pdev);
  1028. out_disable_pdev:
  1029. pci_disable_device(pdev);
  1030. pci_set_drvdata(pdev, NULL);
  1031. return err;
  1032. }
  1033. static inline void t1_sw_reset(struct pci_dev *pdev)
  1034. {
  1035. pci_write_config_dword(pdev, A_PCICFG_PM_CSR, 3);
  1036. pci_write_config_dword(pdev, A_PCICFG_PM_CSR, 0);
  1037. }
  1038. static void __devexit remove_one(struct pci_dev *pdev)
  1039. {
  1040. struct net_device *dev = pci_get_drvdata(pdev);
  1041. if (dev) {
  1042. int i;
  1043. struct adapter *adapter = dev->priv;
  1044. for_each_port(adapter, i)
  1045. if (test_bit(i, &adapter->registered_device_map))
  1046. unregister_netdev(adapter->port[i].dev);
  1047. t1_free_sw_modules(adapter);
  1048. iounmap(adapter->regs);
  1049. while (--i >= 0)
  1050. if (adapter->port[i].dev) {
  1051. cxgb_proc_cleanup(adapter, proc_root_driver);
  1052. kfree(adapter->port[i].dev);
  1053. }
  1054. pci_release_regions(pdev);
  1055. pci_disable_device(pdev);
  1056. pci_set_drvdata(pdev, NULL);
  1057. t1_sw_reset(pdev);
  1058. }
  1059. }
  1060. static struct pci_driver driver = {
  1061. .name = DRV_NAME,
  1062. .id_table = t1_pci_tbl,
  1063. .probe = init_one,
  1064. .remove = __devexit_p(remove_one),
  1065. };
  1066. static int __init t1_init_module(void)
  1067. {
  1068. return pci_register_driver(&driver);
  1069. }
  1070. static void __exit t1_cleanup_module(void)
  1071. {
  1072. pci_unregister_driver(&driver);
  1073. }
  1074. module_init(t1_init_module);
  1075. module_exit(t1_cleanup_module);