islpci_dev.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*
  2. *
  3. * Copyright (C) 2002 Intersil Americas Inc.
  4. * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
  5. * Copyright (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/version.h>
  22. #include <linux/module.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/pci.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/delay.h>
  27. #include <linux/if_arp.h>
  28. #include <asm/io.h>
  29. #include "prismcompat.h"
  30. #include "isl_38xx.h"
  31. #include "isl_ioctl.h"
  32. #include "islpci_dev.h"
  33. #include "islpci_mgt.h"
  34. #include "islpci_eth.h"
  35. #include "oid_mgt.h"
  36. #define ISL3877_IMAGE_FILE "isl3877"
  37. #define ISL3886_IMAGE_FILE "isl3886"
  38. #define ISL3890_IMAGE_FILE "isl3890"
  39. static int prism54_bring_down(islpci_private *);
  40. static int islpci_alloc_memory(islpci_private *);
  41. static struct net_device_stats *islpci_statistics(struct net_device *);
  42. /* Temporary dummy MAC address to use until firmware is loaded.
  43. * The idea there is that some tools (such as nameif) may query
  44. * the MAC address before the netdev is 'open'. By using a valid
  45. * OUI prefix, they can process the netdev properly.
  46. * Of course, this is not the final/real MAC address. It doesn't
  47. * matter, as you are suppose to be able to change it anytime via
  48. * ndev->set_mac_address. Jean II */
  49. static const unsigned char dummy_mac[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
  50. static int
  51. isl_upload_firmware(islpci_private *priv)
  52. {
  53. u32 reg, rc;
  54. void __iomem *device_base = priv->device_base;
  55. /* clear the RAMBoot and the Reset bit */
  56. reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
  57. reg &= ~ISL38XX_CTRL_STAT_RESET;
  58. reg &= ~ISL38XX_CTRL_STAT_RAMBOOT;
  59. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  60. wmb();
  61. udelay(ISL38XX_WRITEIO_DELAY);
  62. /* set the Reset bit without reading the register ! */
  63. reg |= ISL38XX_CTRL_STAT_RESET;
  64. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  65. wmb();
  66. udelay(ISL38XX_WRITEIO_DELAY);
  67. /* clear the Reset bit */
  68. reg &= ~ISL38XX_CTRL_STAT_RESET;
  69. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  70. wmb();
  71. /* wait a while for the device to reboot */
  72. mdelay(50);
  73. {
  74. const struct firmware *fw_entry = NULL;
  75. long fw_len;
  76. const u32 *fw_ptr;
  77. rc = request_firmware(&fw_entry, priv->firmware, PRISM_FW_PDEV);
  78. if (rc) {
  79. printk(KERN_ERR
  80. "%s: request_firmware() failed for '%s'\n",
  81. "prism54", priv->firmware);
  82. return rc;
  83. }
  84. /* prepare the Direct Memory Base register */
  85. reg = ISL38XX_DEV_FIRMWARE_ADDRES;
  86. fw_ptr = (u32 *) fw_entry->data;
  87. fw_len = fw_entry->size;
  88. if (fw_len % 4) {
  89. printk(KERN_ERR
  90. "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
  91. "prism54", priv->firmware);
  92. release_firmware(fw_entry);
  93. return -EILSEQ; /* Illegal byte sequence */;
  94. }
  95. while (fw_len > 0) {
  96. long _fw_len =
  97. (fw_len >
  98. ISL38XX_MEMORY_WINDOW_SIZE) ?
  99. ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
  100. u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
  101. /* set the cards base address for writting the data */
  102. isl38xx_w32_flush(device_base, reg,
  103. ISL38XX_DIR_MEM_BASE_REG);
  104. wmb(); /* be paranoid */
  105. /* increment the write address for next iteration */
  106. reg += _fw_len;
  107. fw_len -= _fw_len;
  108. /* write the data to the Direct Memory Window 32bit-wise */
  109. /* memcpy_toio() doesn't guarantee 32bit writes :-| */
  110. while (_fw_len > 0) {
  111. /* use non-swapping writel() */
  112. __raw_writel(*fw_ptr, dev_fw_ptr);
  113. fw_ptr++, dev_fw_ptr++;
  114. _fw_len -= 4;
  115. }
  116. /* flush PCI posting */
  117. (void) readl(device_base + ISL38XX_PCI_POSTING_FLUSH);
  118. wmb(); /* be paranoid again */
  119. BUG_ON(_fw_len != 0);
  120. }
  121. BUG_ON(fw_len != 0);
  122. /* Firmware version is at offset 40 (also for "newmac") */
  123. printk(KERN_DEBUG "%s: firmware version: %.8s\n",
  124. priv->ndev->name, fw_entry->data + 40);
  125. release_firmware(fw_entry);
  126. }
  127. /* now reset the device
  128. * clear the Reset & ClkRun bit, set the RAMBoot bit */
  129. reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
  130. reg &= ~ISL38XX_CTRL_STAT_CLKRUN;
  131. reg &= ~ISL38XX_CTRL_STAT_RESET;
  132. reg |= ISL38XX_CTRL_STAT_RAMBOOT;
  133. isl38xx_w32_flush(device_base, reg, ISL38XX_CTRL_STAT_REG);
  134. wmb();
  135. udelay(ISL38XX_WRITEIO_DELAY);
  136. /* set the reset bit latches the host override and RAMBoot bits
  137. * into the device for operation when the reset bit is reset */
  138. reg |= ISL38XX_CTRL_STAT_RESET;
  139. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  140. /* don't do flush PCI posting here! */
  141. wmb();
  142. udelay(ISL38XX_WRITEIO_DELAY);
  143. /* clear the reset bit should start the whole circus */
  144. reg &= ~ISL38XX_CTRL_STAT_RESET;
  145. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  146. /* don't do flush PCI posting here! */
  147. wmb();
  148. udelay(ISL38XX_WRITEIO_DELAY);
  149. return 0;
  150. }
  151. /******************************************************************************
  152. Device Interrupt Handler
  153. ******************************************************************************/
  154. irqreturn_t
  155. islpci_interrupt(int irq, void *config, struct pt_regs *regs)
  156. {
  157. u32 reg;
  158. islpci_private *priv = config;
  159. struct net_device *ndev = priv->ndev;
  160. void __iomem *device = priv->device_base;
  161. int powerstate = ISL38XX_PSM_POWERSAVE_STATE;
  162. /* lock the interrupt handler */
  163. spin_lock(&priv->slock);
  164. /* received an interrupt request on a shared IRQ line
  165. * first check whether the device is in sleep mode */
  166. reg = readl(device + ISL38XX_CTRL_STAT_REG);
  167. if (reg & ISL38XX_CTRL_STAT_SLEEPMODE)
  168. /* device is in sleep mode, IRQ was generated by someone else */
  169. {
  170. #if VERBOSE > SHOW_ERROR_MESSAGES
  171. DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
  172. #endif
  173. spin_unlock(&priv->slock);
  174. return IRQ_NONE;
  175. }
  176. /* check whether there is any source of interrupt on the device */
  177. reg = readl(device + ISL38XX_INT_IDENT_REG);
  178. /* also check the contents of the Interrupt Enable Register, because this
  179. * will filter out interrupt sources from other devices on the same irq ! */
  180. reg &= readl(device + ISL38XX_INT_EN_REG);
  181. reg &= ISL38XX_INT_SOURCES;
  182. if (reg != 0) {
  183. if (islpci_get_state(priv) != PRV_STATE_SLEEP)
  184. powerstate = ISL38XX_PSM_ACTIVE_STATE;
  185. /* reset the request bits in the Identification register */
  186. isl38xx_w32_flush(device, reg, ISL38XX_INT_ACK_REG);
  187. #if VERBOSE > SHOW_ERROR_MESSAGES
  188. DEBUG(SHOW_FUNCTION_CALLS,
  189. "IRQ: Identification register 0x%p 0x%x \n", device, reg);
  190. #endif
  191. /* check for each bit in the register separately */
  192. if (reg & ISL38XX_INT_IDENT_UPDATE) {
  193. #if VERBOSE > SHOW_ERROR_MESSAGES
  194. /* Queue has been updated */
  195. DEBUG(SHOW_TRACING, "IRQ: Update flag \n");
  196. DEBUG(SHOW_QUEUE_INDEXES,
  197. "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
  198. le32_to_cpu(priv->control_block->
  199. driver_curr_frag[0]),
  200. le32_to_cpu(priv->control_block->
  201. driver_curr_frag[1]),
  202. le32_to_cpu(priv->control_block->
  203. driver_curr_frag[2]),
  204. le32_to_cpu(priv->control_block->
  205. driver_curr_frag[3]),
  206. le32_to_cpu(priv->control_block->
  207. driver_curr_frag[4]),
  208. le32_to_cpu(priv->control_block->
  209. driver_curr_frag[5])
  210. );
  211. DEBUG(SHOW_QUEUE_INDEXES,
  212. "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
  213. le32_to_cpu(priv->control_block->
  214. device_curr_frag[0]),
  215. le32_to_cpu(priv->control_block->
  216. device_curr_frag[1]),
  217. le32_to_cpu(priv->control_block->
  218. device_curr_frag[2]),
  219. le32_to_cpu(priv->control_block->
  220. device_curr_frag[3]),
  221. le32_to_cpu(priv->control_block->
  222. device_curr_frag[4]),
  223. le32_to_cpu(priv->control_block->
  224. device_curr_frag[5])
  225. );
  226. #endif
  227. /* cleanup the data low transmit queue */
  228. islpci_eth_cleanup_transmit(priv, priv->control_block);
  229. /* device is in active state, update the
  230. * powerstate flag if necessary */
  231. powerstate = ISL38XX_PSM_ACTIVE_STATE;
  232. /* check all three queues in priority order
  233. * call the PIMFOR receive function until the
  234. * queue is empty */
  235. if (isl38xx_in_queue(priv->control_block,
  236. ISL38XX_CB_RX_MGMTQ) != 0) {
  237. #if VERBOSE > SHOW_ERROR_MESSAGES
  238. DEBUG(SHOW_TRACING,
  239. "Received frame in Management Queue\n");
  240. #endif
  241. islpci_mgt_receive(ndev);
  242. islpci_mgt_cleanup_transmit(ndev);
  243. /* Refill slots in receive queue */
  244. islpci_mgmt_rx_fill(ndev);
  245. /* no need to trigger the device, next
  246. islpci_mgt_transaction does it */
  247. }
  248. while (isl38xx_in_queue(priv->control_block,
  249. ISL38XX_CB_RX_DATA_LQ) != 0) {
  250. #if VERBOSE > SHOW_ERROR_MESSAGES
  251. DEBUG(SHOW_TRACING,
  252. "Received frame in Data Low Queue \n");
  253. #endif
  254. islpci_eth_receive(priv);
  255. }
  256. /* check whether the data transmit queues were full */
  257. if (priv->data_low_tx_full) {
  258. /* check whether the transmit is not full anymore */
  259. if (ISL38XX_CB_TX_QSIZE -
  260. isl38xx_in_queue(priv->control_block,
  261. ISL38XX_CB_TX_DATA_LQ) >=
  262. ISL38XX_MIN_QTHRESHOLD) {
  263. /* nope, the driver is ready for more network frames */
  264. netif_wake_queue(priv->ndev);
  265. /* reset the full flag */
  266. priv->data_low_tx_full = 0;
  267. }
  268. }
  269. }
  270. if (reg & ISL38XX_INT_IDENT_INIT) {
  271. /* Device has been initialized */
  272. #if VERBOSE > SHOW_ERROR_MESSAGES
  273. DEBUG(SHOW_TRACING,
  274. "IRQ: Init flag, device initialized \n");
  275. #endif
  276. wake_up(&priv->reset_done);
  277. }
  278. if (reg & ISL38XX_INT_IDENT_SLEEP) {
  279. /* Device intends to move to powersave state */
  280. #if VERBOSE > SHOW_ERROR_MESSAGES
  281. DEBUG(SHOW_TRACING, "IRQ: Sleep flag \n");
  282. #endif
  283. isl38xx_handle_sleep_request(priv->control_block,
  284. &powerstate,
  285. priv->device_base);
  286. }
  287. if (reg & ISL38XX_INT_IDENT_WAKEUP) {
  288. /* Device has been woken up to active state */
  289. #if VERBOSE > SHOW_ERROR_MESSAGES
  290. DEBUG(SHOW_TRACING, "IRQ: Wakeup flag \n");
  291. #endif
  292. isl38xx_handle_wakeup(priv->control_block,
  293. &powerstate, priv->device_base);
  294. }
  295. } else {
  296. #if VERBOSE > SHOW_ERROR_MESSAGES
  297. DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
  298. #endif
  299. spin_unlock(&priv->slock);
  300. return IRQ_NONE;
  301. }
  302. /* sleep -> ready */
  303. if (islpci_get_state(priv) == PRV_STATE_SLEEP
  304. && powerstate == ISL38XX_PSM_ACTIVE_STATE)
  305. islpci_set_state(priv, PRV_STATE_READY);
  306. /* !sleep -> sleep */
  307. if (islpci_get_state(priv) != PRV_STATE_SLEEP
  308. && powerstate == ISL38XX_PSM_POWERSAVE_STATE)
  309. islpci_set_state(priv, PRV_STATE_SLEEP);
  310. /* unlock the interrupt handler */
  311. spin_unlock(&priv->slock);
  312. return IRQ_HANDLED;
  313. }
  314. /******************************************************************************
  315. Network Interface Control & Statistical functions
  316. ******************************************************************************/
  317. static int
  318. islpci_open(struct net_device *ndev)
  319. {
  320. u32 rc;
  321. islpci_private *priv = netdev_priv(ndev);
  322. /* reset data structures, upload firmware and reset device */
  323. rc = islpci_reset(priv,1);
  324. if (rc) {
  325. prism54_bring_down(priv);
  326. return rc; /* Returns informative message */
  327. }
  328. netif_start_queue(ndev);
  329. /* netif_mark_up( ndev ); */
  330. return 0;
  331. }
  332. static int
  333. islpci_close(struct net_device *ndev)
  334. {
  335. islpci_private *priv = netdev_priv(ndev);
  336. printk(KERN_DEBUG "%s: islpci_close ()\n", ndev->name);
  337. netif_stop_queue(ndev);
  338. return prism54_bring_down(priv);
  339. }
  340. static int
  341. prism54_bring_down(islpci_private *priv)
  342. {
  343. void __iomem *device_base = priv->device_base;
  344. u32 reg;
  345. /* we are going to shutdown the device */
  346. islpci_set_state(priv, PRV_STATE_PREBOOT);
  347. /* disable all device interrupts in case they weren't */
  348. isl38xx_disable_interrupts(priv->device_base);
  349. /* For safety reasons, we may want to ensure that no DMA transfer is
  350. * currently in progress by emptying the TX and RX queues. */
  351. /* wait until interrupts have finished executing on other CPUs */
  352. synchronize_irq(priv->pdev->irq);
  353. reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
  354. reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
  355. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  356. wmb();
  357. udelay(ISL38XX_WRITEIO_DELAY);
  358. reg |= ISL38XX_CTRL_STAT_RESET;
  359. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  360. wmb();
  361. udelay(ISL38XX_WRITEIO_DELAY);
  362. /* clear the Reset bit */
  363. reg &= ~ISL38XX_CTRL_STAT_RESET;
  364. writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
  365. wmb();
  366. /* wait a while for the device to reset */
  367. schedule_timeout_uninterruptible(msecs_to_jiffies(50));
  368. return 0;
  369. }
  370. static int
  371. islpci_upload_fw(islpci_private *priv)
  372. {
  373. islpci_state_t old_state;
  374. u32 rc;
  375. old_state = islpci_set_state(priv, PRV_STATE_BOOT);
  376. printk(KERN_DEBUG "%s: uploading firmware...\n", priv->ndev->name);
  377. rc = isl_upload_firmware(priv);
  378. if (rc) {
  379. /* error uploading the firmware */
  380. printk(KERN_ERR "%s: could not upload firmware ('%s')\n",
  381. priv->ndev->name, priv->firmware);
  382. islpci_set_state(priv, old_state);
  383. return rc;
  384. }
  385. printk(KERN_DEBUG "%s: firmware upload complete\n",
  386. priv->ndev->name);
  387. islpci_set_state(priv, PRV_STATE_POSTBOOT);
  388. return 0;
  389. }
  390. static int
  391. islpci_reset_if(islpci_private *priv)
  392. {
  393. long remaining;
  394. int result = -ETIME;
  395. int count;
  396. DEFINE_WAIT(wait);
  397. prepare_to_wait(&priv->reset_done, &wait, TASK_UNINTERRUPTIBLE);
  398. /* now the last step is to reset the interface */
  399. isl38xx_interface_reset(priv->device_base, priv->device_host_address);
  400. islpci_set_state(priv, PRV_STATE_PREINIT);
  401. for(count = 0; count < 2 && result; count++) {
  402. /* The software reset acknowledge needs about 220 msec here.
  403. * Be conservative and wait for up to one second. */
  404. remaining = schedule_timeout_uninterruptible(HZ);
  405. if(remaining > 0) {
  406. result = 0;
  407. break;
  408. }
  409. /* If we're here it's because our IRQ hasn't yet gone through.
  410. * Retry a bit more...
  411. */
  412. printk(KERN_ERR "%s: no 'reset complete' IRQ seen - retrying\n",
  413. priv->ndev->name);
  414. }
  415. finish_wait(&priv->reset_done, &wait);
  416. if (result) {
  417. printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
  418. return result;
  419. }
  420. islpci_set_state(priv, PRV_STATE_INIT);
  421. /* Now that the device is 100% up, let's allow
  422. * for the other interrupts --
  423. * NOTE: this is not *yet* true since we've only allowed the
  424. * INIT interrupt on the IRQ line. We can perhaps poll
  425. * the IRQ line until we know for sure the reset went through */
  426. isl38xx_enable_common_interrupts(priv->device_base);
  427. down_write(&priv->mib_sem);
  428. result = mgt_commit(priv);
  429. if (result) {
  430. printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
  431. up_write(&priv->mib_sem);
  432. return result;
  433. }
  434. up_write(&priv->mib_sem);
  435. islpci_set_state(priv, PRV_STATE_READY);
  436. printk(KERN_DEBUG "%s: interface reset complete\n", priv->ndev->name);
  437. return 0;
  438. }
  439. int
  440. islpci_reset(islpci_private *priv, int reload_firmware)
  441. {
  442. isl38xx_control_block *cb = /* volatile not needed */
  443. (isl38xx_control_block *) priv->control_block;
  444. unsigned counter;
  445. int rc;
  446. if (reload_firmware)
  447. islpci_set_state(priv, PRV_STATE_PREBOOT);
  448. else
  449. islpci_set_state(priv, PRV_STATE_POSTBOOT);
  450. printk(KERN_DEBUG "%s: resetting device...\n", priv->ndev->name);
  451. /* disable all device interrupts in case they weren't */
  452. isl38xx_disable_interrupts(priv->device_base);
  453. /* flush all management queues */
  454. priv->index_mgmt_tx = 0;
  455. priv->index_mgmt_rx = 0;
  456. /* clear the indexes in the frame pointer */
  457. for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
  458. cb->driver_curr_frag[counter] = cpu_to_le32(0);
  459. cb->device_curr_frag[counter] = cpu_to_le32(0);
  460. }
  461. /* reset the mgmt receive queue */
  462. for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
  463. isl38xx_fragment *frag = &cb->rx_data_mgmt[counter];
  464. frag->size = cpu_to_le16(MGMT_FRAME_SIZE);
  465. frag->flags = 0;
  466. frag->address = cpu_to_le32(priv->mgmt_rx[counter].pci_addr);
  467. }
  468. for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
  469. cb->rx_data_low[counter].address =
  470. cpu_to_le32((u32) priv->pci_map_rx_address[counter]);
  471. }
  472. /* since the receive queues are filled with empty fragments, now we can
  473. * set the corresponding indexes in the Control Block */
  474. priv->control_block->driver_curr_frag[ISL38XX_CB_RX_DATA_LQ] =
  475. cpu_to_le32(ISL38XX_CB_RX_QSIZE);
  476. priv->control_block->driver_curr_frag[ISL38XX_CB_RX_MGMTQ] =
  477. cpu_to_le32(ISL38XX_CB_MGMT_QSIZE);
  478. /* reset the remaining real index registers and full flags */
  479. priv->free_data_rx = 0;
  480. priv->free_data_tx = 0;
  481. priv->data_low_tx_full = 0;
  482. if (reload_firmware) { /* Should we load the firmware ? */
  483. /* now that the data structures are cleaned up, upload
  484. * firmware and reset interface */
  485. rc = islpci_upload_fw(priv);
  486. if (rc) {
  487. printk(KERN_ERR "%s: islpci_reset: failure\n",
  488. priv->ndev->name);
  489. return rc;
  490. }
  491. }
  492. /* finally reset interface */
  493. rc = islpci_reset_if(priv);
  494. if (rc)
  495. printk(KERN_ERR "prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
  496. return rc;
  497. }
  498. static struct net_device_stats *
  499. islpci_statistics(struct net_device *ndev)
  500. {
  501. islpci_private *priv = netdev_priv(ndev);
  502. #if VERBOSE > SHOW_ERROR_MESSAGES
  503. DEBUG(SHOW_FUNCTION_CALLS, "islpci_statistics\n");
  504. #endif
  505. return &priv->statistics;
  506. }
  507. /******************************************************************************
  508. Network device configuration functions
  509. ******************************************************************************/
  510. static int
  511. islpci_alloc_memory(islpci_private *priv)
  512. {
  513. int counter;
  514. #if VERBOSE > SHOW_ERROR_MESSAGES
  515. printk(KERN_DEBUG "islpci_alloc_memory\n");
  516. #endif
  517. /* remap the PCI device base address to accessable */
  518. if (!(priv->device_base =
  519. ioremap(pci_resource_start(priv->pdev, 0),
  520. ISL38XX_PCI_MEM_SIZE))) {
  521. /* error in remapping the PCI device memory address range */
  522. printk(KERN_ERR "PCI memory remapping failed \n");
  523. return -1;
  524. }
  525. /* memory layout for consistent DMA region:
  526. *
  527. * Area 1: Control Block for the device interface
  528. * Area 2: Power Save Mode Buffer for temporary frame storage. Be aware that
  529. * the number of supported stations in the AP determines the minimal
  530. * size of the buffer !
  531. */
  532. /* perform the allocation */
  533. priv->driver_mem_address = pci_alloc_consistent(priv->pdev,
  534. HOST_MEM_BLOCK,
  535. &priv->
  536. device_host_address);
  537. if (!priv->driver_mem_address) {
  538. /* error allocating the block of PCI memory */
  539. printk(KERN_ERR "%s: could not allocate DMA memory, aborting!",
  540. "prism54");
  541. return -1;
  542. }
  543. /* assign the Control Block to the first address of the allocated area */
  544. priv->control_block =
  545. (isl38xx_control_block *) priv->driver_mem_address;
  546. /* set the Power Save Buffer pointer directly behind the CB */
  547. priv->device_psm_buffer =
  548. priv->device_host_address + CONTROL_BLOCK_SIZE;
  549. /* make sure all buffer pointers are initialized */
  550. for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
  551. priv->control_block->driver_curr_frag[counter] = cpu_to_le32(0);
  552. priv->control_block->device_curr_frag[counter] = cpu_to_le32(0);
  553. }
  554. priv->index_mgmt_rx = 0;
  555. memset(priv->mgmt_rx, 0, sizeof(priv->mgmt_rx));
  556. memset(priv->mgmt_tx, 0, sizeof(priv->mgmt_tx));
  557. /* allocate rx queue for management frames */
  558. if (islpci_mgmt_rx_fill(priv->ndev) < 0)
  559. goto out_free;
  560. /* now get the data rx skb's */
  561. memset(priv->data_low_rx, 0, sizeof (priv->data_low_rx));
  562. memset(priv->pci_map_rx_address, 0, sizeof (priv->pci_map_rx_address));
  563. for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
  564. struct sk_buff *skb;
  565. /* allocate an sk_buff for received data frames storage
  566. * each frame on receive size consists of 1 fragment
  567. * include any required allignment operations */
  568. if (!(skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2))) {
  569. /* error allocating an sk_buff structure elements */
  570. printk(KERN_ERR "Error allocating skb.\n");
  571. skb = NULL;
  572. goto out_free;
  573. }
  574. skb_reserve(skb, (4 - (long) skb->data) & 0x03);
  575. /* add the new allocated sk_buff to the buffer array */
  576. priv->data_low_rx[counter] = skb;
  577. /* map the allocated skb data area to pci */
  578. priv->pci_map_rx_address[counter] =
  579. pci_map_single(priv->pdev, (void *) skb->data,
  580. MAX_FRAGMENT_SIZE_RX + 2,
  581. PCI_DMA_FROMDEVICE);
  582. if (!priv->pci_map_rx_address[counter]) {
  583. /* error mapping the buffer to device
  584. accessable memory address */
  585. printk(KERN_ERR "failed to map skb DMA'able\n");
  586. goto out_free;
  587. }
  588. }
  589. prism54_acl_init(&priv->acl);
  590. prism54_wpa_ie_init(priv);
  591. if (mgt_init(priv))
  592. goto out_free;
  593. return 0;
  594. out_free:
  595. islpci_free_memory(priv);
  596. return -1;
  597. }
  598. int
  599. islpci_free_memory(islpci_private *priv)
  600. {
  601. int counter;
  602. if (priv->device_base)
  603. iounmap(priv->device_base);
  604. priv->device_base = NULL;
  605. /* free consistent DMA area... */
  606. if (priv->driver_mem_address)
  607. pci_free_consistent(priv->pdev, HOST_MEM_BLOCK,
  608. priv->driver_mem_address,
  609. priv->device_host_address);
  610. /* clear some dangling pointers */
  611. priv->driver_mem_address = NULL;
  612. priv->device_host_address = 0;
  613. priv->device_psm_buffer = 0;
  614. priv->control_block = NULL;
  615. /* clean up mgmt rx buffers */
  616. for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
  617. struct islpci_membuf *buf = &priv->mgmt_rx[counter];
  618. if (buf->pci_addr)
  619. pci_unmap_single(priv->pdev, buf->pci_addr,
  620. buf->size, PCI_DMA_FROMDEVICE);
  621. buf->pci_addr = 0;
  622. kfree(buf->mem);
  623. buf->size = 0;
  624. buf->mem = NULL;
  625. }
  626. /* clean up data rx buffers */
  627. for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
  628. if (priv->pci_map_rx_address[counter])
  629. pci_unmap_single(priv->pdev,
  630. priv->pci_map_rx_address[counter],
  631. MAX_FRAGMENT_SIZE_RX + 2,
  632. PCI_DMA_FROMDEVICE);
  633. priv->pci_map_rx_address[counter] = 0;
  634. if (priv->data_low_rx[counter])
  635. dev_kfree_skb(priv->data_low_rx[counter]);
  636. priv->data_low_rx[counter] = NULL;
  637. }
  638. /* Free the acces control list and the WPA list */
  639. prism54_acl_clean(&priv->acl);
  640. prism54_wpa_ie_clean(priv);
  641. mgt_clean(priv);
  642. return 0;
  643. }
  644. #if 0
  645. static void
  646. islpci_set_multicast_list(struct net_device *dev)
  647. {
  648. /* put device into promisc mode and let network layer handle it */
  649. }
  650. #endif
  651. struct net_device *
  652. islpci_setup(struct pci_dev *pdev)
  653. {
  654. islpci_private *priv;
  655. struct net_device *ndev = alloc_etherdev(sizeof (islpci_private));
  656. if (!ndev)
  657. return ndev;
  658. SET_MODULE_OWNER(ndev);
  659. pci_set_drvdata(pdev, ndev);
  660. #if defined(SET_NETDEV_DEV)
  661. SET_NETDEV_DEV(ndev, &pdev->dev);
  662. #endif
  663. /* setup the structure members */
  664. ndev->base_addr = pci_resource_start(pdev, 0);
  665. ndev->irq = pdev->irq;
  666. /* initialize the function pointers */
  667. ndev->open = &islpci_open;
  668. ndev->stop = &islpci_close;
  669. ndev->get_stats = &islpci_statistics;
  670. ndev->do_ioctl = &prism54_ioctl;
  671. ndev->wireless_handlers =
  672. (struct iw_handler_def *) &prism54_handler_def;
  673. ndev->hard_start_xmit = &islpci_eth_transmit;
  674. /* ndev->set_multicast_list = &islpci_set_multicast_list; */
  675. ndev->addr_len = ETH_ALEN;
  676. ndev->set_mac_address = &prism54_set_mac_address;
  677. /* Get a non-zero dummy MAC address for nameif. Jean II */
  678. memcpy(ndev->dev_addr, dummy_mac, 6);
  679. #ifdef HAVE_TX_TIMEOUT
  680. ndev->watchdog_timeo = ISLPCI_TX_TIMEOUT;
  681. ndev->tx_timeout = &islpci_eth_tx_timeout;
  682. #endif
  683. /* allocate a private device structure to the network device */
  684. priv = netdev_priv(ndev);
  685. priv->ndev = ndev;
  686. priv->pdev = pdev;
  687. priv->monitor_type = ARPHRD_IEEE80211;
  688. priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
  689. priv->monitor_type : ARPHRD_ETHER;
  690. /* Add pointers to enable iwspy support. */
  691. priv->wireless_data.spy_data = &priv->spy_data;
  692. ndev->wireless_data = &priv->wireless_data;
  693. /* save the start and end address of the PCI memory area */
  694. ndev->mem_start = (unsigned long) priv->device_base;
  695. ndev->mem_end = ndev->mem_start + ISL38XX_PCI_MEM_SIZE;
  696. #if VERBOSE > SHOW_ERROR_MESSAGES
  697. DEBUG(SHOW_TRACING, "PCI Memory remapped to 0x%p\n", priv->device_base);
  698. #endif
  699. init_waitqueue_head(&priv->reset_done);
  700. /* init the queue read locks, process wait counter */
  701. sema_init(&priv->mgmt_sem, 1);
  702. priv->mgmt_received = NULL;
  703. init_waitqueue_head(&priv->mgmt_wqueue);
  704. sema_init(&priv->stats_sem, 1);
  705. spin_lock_init(&priv->slock);
  706. /* init state machine with off#1 state */
  707. priv->state = PRV_STATE_OFF;
  708. priv->state_off = 1;
  709. /* initialize workqueue's */
  710. INIT_WORK(&priv->stats_work,
  711. (void (*)(void *)) prism54_update_stats, priv);
  712. priv->stats_timestamp = 0;
  713. INIT_WORK(&priv->reset_task, islpci_do_reset_and_wake, priv);
  714. priv->reset_task_pending = 0;
  715. /* allocate various memory areas */
  716. if (islpci_alloc_memory(priv))
  717. goto do_free_netdev;
  718. /* select the firmware file depending on the device id */
  719. switch (pdev->device) {
  720. case 0x3877:
  721. strcpy(priv->firmware, ISL3877_IMAGE_FILE);
  722. break;
  723. case 0x3886:
  724. strcpy(priv->firmware, ISL3886_IMAGE_FILE);
  725. break;
  726. default:
  727. strcpy(priv->firmware, ISL3890_IMAGE_FILE);
  728. break;
  729. }
  730. if (register_netdev(ndev)) {
  731. DEBUG(SHOW_ERROR_MESSAGES,
  732. "ERROR: register_netdev() failed \n");
  733. goto do_islpci_free_memory;
  734. }
  735. return ndev;
  736. do_islpci_free_memory:
  737. islpci_free_memory(priv);
  738. do_free_netdev:
  739. pci_set_drvdata(pdev, NULL);
  740. free_netdev(ndev);
  741. priv = NULL;
  742. return NULL;
  743. }
  744. islpci_state_t
  745. islpci_set_state(islpci_private *priv, islpci_state_t new_state)
  746. {
  747. islpci_state_t old_state;
  748. /* lock */
  749. old_state = priv->state;
  750. /* this means either a race condition or some serious error in
  751. * the driver code */
  752. switch (new_state) {
  753. case PRV_STATE_OFF:
  754. priv->state_off++;
  755. default:
  756. priv->state = new_state;
  757. break;
  758. case PRV_STATE_PREBOOT:
  759. /* there are actually many off-states, enumerated by
  760. * state_off */
  761. if (old_state == PRV_STATE_OFF)
  762. priv->state_off--;
  763. /* only if hw_unavailable is zero now it means we either
  764. * were in off#1 state, or came here from
  765. * somewhere else */
  766. if (!priv->state_off)
  767. priv->state = new_state;
  768. break;
  769. };
  770. #if 0
  771. printk(KERN_DEBUG "%s: state transition %d -> %d (off#%d)\n",
  772. priv->ndev->name, old_state, new_state, priv->state_off);
  773. #endif
  774. /* invariants */
  775. BUG_ON(priv->state_off < 0);
  776. BUG_ON(priv->state_off && (priv->state != PRV_STATE_OFF));
  777. BUG_ON(!priv->state_off && (priv->state == PRV_STATE_OFF));
  778. /* unlock */
  779. return old_state;
  780. }