注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

BCB-DG's Blog

...

 
 
 

日志

 
 

Linux/drivers/net/wireless/rtl818x/rtl8187/dev.c (2)  

2014-04-23 15:02:53|  分类: Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
1055 
1056 static void rtl8187_beacon_work(struct work_struct *work)
1057 {
1058         struct rtl8187_vif *vif_priv =
1059                 container_of(work, struct rtl8187_vif, beacon_work.work);
1060         struct ieee80211_vif *vif =
1061                 container_of((void *)vif_priv, struct ieee80211_vif, drv_priv);
1062         struct ieee80211_hw *dev = vif_priv->dev;
1063         struct ieee80211_mgmt *mgmt;
1064         struct sk_buff *skb;
1065 
1066         /* don't overflow the tx ring */
1067         if (ieee80211_queue_stopped(dev, 0))
1068                 goto resched;
1069 
1070         /* grab a fresh beacon */
1071         skb = ieee80211_beacon_get(dev, vif);
1072         if (!skb)
1073                 goto resched;
1074 
1075         /*
1076          * update beacon timestamp w/ TSF value
1077          * TODO: make hardware update beacon timestamp
1078          */
1079         mgmt = (struct ieee80211_mgmt *)skb->data;
1080         mgmt->u.beacon.timestamp = cpu_to_le64(rtl8187_get_tsf(dev, vif));
1081 
1082         /* TODO: use actual beacon queue */
1083         skb_set_queue_mapping(skb, 0);
1084 
1085         rtl8187_tx(dev, NULL, skb);
1086 
1087 resched:
1088         /*
1089          * schedule next beacon
1090          * TODO: use hardware support for beacon timing
1091          */
1092         schedule_delayed_work(&vif_priv->beacon_work,
1093                         usecs_to_jiffies(1024 * vif->bss_conf.beacon_int));
1094 }
1095 
1096 
1097 static int rtl8187_add_interface(struct ieee80211_hw *dev,
1098                                  struct ieee80211_vif *vif)
1099 {
1100         struct rtl8187_priv *priv = dev->priv;
1101         struct rtl8187_vif *vif_priv;
1102         int i;
1103         int ret = -EOPNOTSUPP;
1104 
1105         mutex_lock(&priv->conf_mutex);
1106         if (priv->vif)
1107                 goto exit;
1108 
1109         switch (vif->type) {
1110         case NL80211_IFTYPE_STATION:
1111         case NL80211_IFTYPE_ADHOC:
1112                 break;
1113         default:
1114                 goto exit;
1115         }
1116 
1117         ret = 0;
1118         priv->vif = vif;
1119 
1120         /* Initialize driver private area */
1121         vif_priv = (struct rtl8187_vif *)&vif->drv_priv;
1122         vif_priv->dev = dev;
1123         INIT_DELAYED_WORK(&vif_priv->beacon_work, rtl8187_beacon_work);
1124         vif_priv->enable_beacon = false;
1125 
1126 
1127         rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
1128         for (i = 0; i < ETH_ALEN; i++)
1129                 rtl818x_iowrite8(priv, &priv->map->MAC[i],
1130                                  ((u8 *)vif->addr)[i]);
1131         rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
1132 
1133 exit:
1134         mutex_unlock(&priv->conf_mutex);
1135         return ret;
1136 }
1137 
1138 static void rtl8187_remove_interface(struct ieee80211_hw *dev,
1139                                      struct ieee80211_vif *vif)
1140 {
1141         struct rtl8187_priv *priv = dev->priv;
1142         mutex_lock(&priv->conf_mutex);
1143         priv->vif = NULL;
1144         mutex_unlock(&priv->conf_mutex);
1145 }
1146 
1147 static int rtl8187_config(struct ieee80211_hw *dev, u32 changed)
1148 {
1149         struct rtl8187_priv *priv = dev->priv;
1150         struct ieee80211_conf *conf = &dev->conf;
1151         u32 reg;
1152 
1153         mutex_lock(&priv->conf_mutex);
1154         reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
1155         /* Enable TX loopback on MAC level to avoid TX during channel
1156          * changes, as this has be seen to causes problems and the
1157          * card will stop work until next reset
1158          */
1159         rtl818x_iowrite32(priv, &priv->map->TX_CONF,
1160                           reg | RTL818X_TX_CONF_LOOPBACK_MAC);
1161         priv->rf->set_chan(dev, conf);
1162         msleep(10);
1163         rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
1164 
1165         rtl818x_iowrite16(priv, &priv->map->ATIM_WND, 2);
1166         rtl818x_iowrite16(priv, &priv->map->ATIMTR_INTERVAL, 100);
1167         rtl818x_iowrite16(priv, &priv->map->BEACON_INTERVAL, 100);
1168         rtl818x_iowrite16(priv, &priv->map->BEACON_INTERVAL_TIME, 100);
1169         mutex_unlock(&priv->conf_mutex);
1170         return 0;
1171 }
1172 
1173 /*
1174  * With 8187B, AC_*_PARAM clashes with FEMR definition in struct rtl818x_csr for
1175  * example. Thus we have to use raw values for AC_*_PARAM register addresses.
1176  */
1177 static __le32 *rtl8187b_ac_addr[4] = {
1178         (__le32 *) 0xFFF0, /* AC_VO */
1179         (__le32 *) 0xFFF4, /* AC_VI */
1180         (__le32 *) 0xFFFC, /* AC_BK */
1181         (__le32 *) 0xFFF8, /* AC_BE */
1182 };
1183 
1184 #define SIFS_TIME 0xa
1185 
1186 static void rtl8187_conf_erp(struct rtl8187_priv *priv, bool use_short_slot,
1187                              bool use_short_preamble)
1188 {
1189         if (priv->is_rtl8187b) {
1190                 u8 difs, eifs;
1191                 u16 ack_timeout;
1192                 int queue;
1193 
1194                 if (use_short_slot) {
1195                         priv->slot_time = 0x9;
1196                         difs = 0x1c;
1197                         eifs = 0x53;
1198                 } else {
1199                         priv->slot_time = 0x14;
1200                         difs = 0x32;
1201                         eifs = 0x5b;
1202                 }
1203                 rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
1204                 rtl818x_iowrite8(priv, &priv->map->SLOT, priv->slot_time);
1205                 rtl818x_iowrite8(priv, &priv->map->DIFS, difs);
1206 
1207                 /*
1208                  * BRSR+1 on 8187B is in fact EIFS register
1209                  * Value in units of 4 us
1210                  */
1211                 rtl818x_iowrite8(priv, (u8 *)&priv->map->BRSR + 1, eifs);
1212 
1213                 /*
1214                  * For 8187B, CARRIER_SENSE_COUNTER is in fact ack timeout
1215                  * register. In units of 4 us like eifs register
1216                  * ack_timeout = ack duration + plcp + difs + preamble
1217                  */
1218                 ack_timeout = 112 + 48 + difs;
1219                 if (use_short_preamble)
1220                         ack_timeout += 72;
1221                 else
1222                         ack_timeout += 144;
1223                 rtl818x_iowrite8(priv, &priv->map->CARRIER_SENSE_COUNTER,
1224                                  DIV_ROUND_UP(ack_timeout, 4));
1225 
1226                 for (queue = 0; queue < 4; queue++)
1227                         rtl818x_iowrite8(priv, (u8 *) rtl8187b_ac_addr[queue],
1228                                          priv->aifsn[queue] * priv->slot_time +
1229                                          SIFS_TIME);
1230         } else {
1231                 rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
1232                 if (use_short_slot) {
1233                         rtl818x_iowrite8(priv, &priv->map->SLOT, 0x9);
1234                         rtl818x_iowrite8(priv, &priv->map->DIFS, 0x14);
1235                         rtl818x_iowrite8(priv, &priv->map->EIFS, 91 - 0x14);
1236                 } else {
1237                         rtl818x_iowrite8(priv, &priv->map->SLOT, 0x14);
1238                         rtl818x_iowrite8(priv, &priv->map->DIFS, 0x24);
1239                         rtl818x_iowrite8(priv, &priv->map->EIFS, 91 - 0x24);
1240                 }
1241         }
1242 }
1243 
1244 static void rtl8187_bss_info_changed(struct ieee80211_hw *dev,
1245                                      struct ieee80211_vif *vif,
1246                                      struct ieee80211_bss_conf *info,
1247                                      u32 changed)
1248 {
1249         struct rtl8187_priv *priv = dev->priv;
1250         struct rtl8187_vif *vif_priv;
1251         int i;
1252         u8 reg;
1253 
1254         vif_priv = (struct rtl8187_vif *)&vif->drv_priv;
1255 
1256         if (changed & BSS_CHANGED_BSSID) {
1257                 mutex_lock(&priv->conf_mutex);
1258                 for (i = 0; i < ETH_ALEN; i++)
1259                         rtl818x_iowrite8(priv, &priv->map->BSSID[i],
1260                                          info->bssid[i]);
1261 
1262                 if (priv->is_rtl8187b)
1263                         reg = RTL818X_MSR_ENEDCA;
1264                 else
1265                         reg = 0;
1266 
1267                 if (is_valid_ether_addr(info->bssid)) {
1268                         if (vif->type == NL80211_IFTYPE_ADHOC)
1269                                 reg |= RTL818X_MSR_ADHOC;
1270                         else
1271                                 reg |= RTL818X_MSR_INFRA;
1272                 }
1273                 else
1274                         reg |= RTL818X_MSR_NO_LINK;
1275 
1276                 rtl818x_iowrite8(priv, &priv->map->MSR, reg);
1277 
1278                 mutex_unlock(&priv->conf_mutex);
1279         }
1280 
1281         if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_ERP_PREAMBLE))
1282                 rtl8187_conf_erp(priv, info->use_short_slot,
1283                                  info->use_short_preamble);
1284 
1285         if (changed & BSS_CHANGED_BEACON_ENABLED)
1286                 vif_priv->enable_beacon = info->enable_beacon;
1287 
1288         if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON)) {
1289                 cancel_delayed_work_sync(&vif_priv->beacon_work);
1290                 if (vif_priv->enable_beacon)
1291                         schedule_work(&vif_priv->beacon_work.work);
1292         }
1293 
1294 }
1295 
1296 static u64 rtl8187_prepare_multicast(struct ieee80211_hw *dev,
1297                                      struct netdev_hw_addr_list *mc_list)
1298 {
1299         return netdev_hw_addr_list_count(mc_list);
1300 }
1301 
1302 static void rtl8187_configure_filter(struct ieee80211_hw *dev,
1303                                      unsigned int changed_flags,
1304                                      unsigned int *total_flags,
1305                                      u64 multicast)
1306 {
1307         struct rtl8187_priv *priv = dev->priv;
1308 
1309         if (changed_flags & FIF_FCSFAIL)
1310                 priv->rx_conf ^= RTL818X_RX_CONF_FCS;
1311         if (changed_flags & FIF_CONTROL)
1312                 priv->rx_conf ^= RTL818X_RX_CONF_CTRL;
1313         if (changed_flags & FIF_OTHER_BSS)
1314                 priv->rx_conf ^= RTL818X_RX_CONF_MONITOR;
1315         if (*total_flags & FIF_ALLMULTI || multicast > 0)
1316                 priv->rx_conf |= RTL818X_RX_CONF_MULTICAST;
1317         else
1318                 priv->rx_conf &= ~RTL818X_RX_CONF_MULTICAST;
1319 
1320         *total_flags = 0;
1321 
1322         if (priv->rx_conf & RTL818X_RX_CONF_FCS)
1323                 *total_flags |= FIF_FCSFAIL;
1324         if (priv->rx_conf & RTL818X_RX_CONF_CTRL)
1325                 *total_flags |= FIF_CONTROL;
1326         if (priv->rx_conf & RTL818X_RX_CONF_MONITOR)
1327                 *total_flags |= FIF_OTHER_BSS;
1328         if (priv->rx_conf & RTL818X_RX_CONF_MULTICAST)
1329                 *total_flags |= FIF_ALLMULTI;
1330 
1331         rtl818x_iowrite32_async(priv, &priv->map->RX_CONF, priv->rx_conf);
1332 }
1333 
1334 static int rtl8187_conf_tx(struct ieee80211_hw *dev,
1335                            struct ieee80211_vif *vif, u16 queue,
1336                            const struct ieee80211_tx_queue_params *params)
1337 {
1338         struct rtl8187_priv *priv = dev->priv;
1339         u8 cw_min, cw_max;
1340 
1341         if (queue > 3)
1342                 return -EINVAL;
1343 
1344         cw_min = fls(params->cw_min);
1345         cw_max = fls(params->cw_max);
1346 
1347         if (priv->is_rtl8187b) {
1348                 priv->aifsn[queue] = params->aifs;
1349 
1350                 /*
1351                  * This is the structure of AC_*_PARAM registers in 8187B:
1352                  * - TXOP limit field, bit offset = 16
1353                  * - ECWmax, bit offset = 12
1354                  * - ECWmin, bit offset = 8
1355                  * - AIFS, bit offset = 0
1356                  */
1357                 rtl818x_iowrite32(priv, rtl8187b_ac_addr[queue],
1358                                   (params->txop << 16) | (cw_max << 12) |
1359                                   (cw_min << 8) | (params->aifs *
1360                                   priv->slot_time + SIFS_TIME));
1361         } else {
1362                 if (queue != 0)
1363                         return -EINVAL;
1364 
1365                 rtl818x_iowrite8(priv, &priv->map->CW_VAL,
1366                                  cw_min | (cw_max << 4));
1367         }
1368         return 0;
1369 }
1370 
1371 
1372 static const struct ieee80211_ops rtl8187_ops = {
1373         .tx                     = rtl8187_tx,
1374         .start                  = rtl8187_start,
1375         .stop                   = rtl8187_stop,
1376         .add_interface          = rtl8187_add_interface,
1377         .remove_interface       = rtl8187_remove_interface,
1378         .config                 = rtl8187_config,
1379         .bss_info_changed       = rtl8187_bss_info_changed,
1380         .prepare_multicast      = rtl8187_prepare_multicast,
1381         .configure_filter       = rtl8187_configure_filter,
1382         .conf_tx                = rtl8187_conf_tx,
1383         .rfkill_poll            = rtl8187_rfkill_poll,
1384         .get_tsf                = rtl8187_get_tsf,
1385 };
1386 
1387 static void rtl8187_eeprom_register_read(struct eeprom_93cx6 *eeprom)
1388 {
1389         struct ieee80211_hw *dev = eeprom->data;
1390         struct rtl8187_priv *priv = dev->priv;
1391         u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
1392 
1393         eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
1394         eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ;
1395         eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK;
1396         eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS;
1397 }
1398 
1399 static void rtl8187_eeprom_register_write(struct eeprom_93cx6 *eeprom)
1400 {
1401         struct ieee80211_hw *dev = eeprom->data;
1402         struct rtl8187_priv *priv = dev->priv;
1403         u8 reg = RTL818X_EEPROM_CMD_PROGRAM;
1404 
1405         if (eeprom->reg_data_in)
1406                 reg |= RTL818X_EEPROM_CMD_WRITE;
1407         if (eeprom->reg_data_out)
1408                 reg |= RTL818X_EEPROM_CMD_READ;
1409         if (eeprom->reg_data_clock)
1410                 reg |= RTL818X_EEPROM_CMD_CK;
1411         if (eeprom->reg_chip_select)
1412                 reg |= RTL818X_EEPROM_CMD_CS;
1413 
1414         rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, reg);
1415         udelay(10);
1416 }
1417 
1418 static int rtl8187_probe(struct usb_interface *intf,
1419                                    const struct usb_device_id *id)
1420 {
1421         struct usb_device *udev = interface_to_usbdev(intf);
1422         struct ieee80211_hw *dev;
1423         struct rtl8187_priv *priv;
1424         struct eeprom_93cx6 eeprom;
1425         struct ieee80211_channel *channel;
1426         const char *chip_name;
1427         u16 txpwr, reg;
1428         u16 product_id = le16_to_cpu(udev->descriptor.idProduct);
1429         int err, i;
1430         u8 mac_addr[ETH_ALEN];
1431 
1432         dev = ieee80211_alloc_hw(sizeof(*priv), &rtl8187_ops);
1433         if (!dev) {
1434                 printk(KERN_ERR "rtl8187: ieee80211 alloc failed\n");
1435                 return -ENOMEM;
1436         }
1437 
1438         priv = dev->priv;
1439         priv->is_rtl8187b = (id->driver_info == DEVICE_RTL8187B);
1440 
1441         /* allocate "DMA aware" buffer for register accesses */
1442         priv->io_dmabuf = kmalloc(sizeof(*priv->io_dmabuf), GFP_KERNEL);
1443         if (!priv->io_dmabuf) {
1444                 err = -ENOMEM;
1445                 goto err_free_dev;
1446         }
1447         mutex_init(&priv->io_mutex);
1448 
1449         SET_IEEE80211_DEV(dev, &intf->dev);
1450         usb_set_intfdata(intf, dev);
1451         priv->udev = udev;
1452 
1453         usb_get_dev(udev);
1454 
1455         skb_queue_head_init(&priv->rx_queue);
1456 
1457         BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels));
1458         BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates));
1459 
1460         memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels));
1461         memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates));
1462         priv->map = (struct rtl818x_csr *)0xFF00;
1463 
1464         priv->band.band = IEEE80211_BAND_2GHZ;
1465         priv->band.channels = priv->channels;
1466         priv->band.n_channels = ARRAY_SIZE(rtl818x_channels);
1467         priv->band.bitrates = priv->rates;
1468         priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates);
1469         dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
1470 
1471 
1472         dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1473                      IEEE80211_HW_SIGNAL_DBM |
1474                      IEEE80211_HW_RX_INCLUDES_FCS;
1475         /* Initialize rate-control variables */
1476         dev->max_rates = 1;
1477         dev->max_rate_tries = RETRY_COUNT;
1478 
1479         eeprom.data = dev;
1480         eeprom.register_read = rtl8187_eeprom_register_read;
1481         eeprom.register_write = rtl8187_eeprom_register_write;
1482         if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
1483                 eeprom.width = PCI_EEPROM_WIDTH_93C66;
1484         else
1485                 eeprom.width = PCI_EEPROM_WIDTH_93C46;
1486 
1487         rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
1488         udelay(10);
1489 
1490         eeprom_93cx6_multiread(&eeprom, RTL8187_EEPROM_MAC_ADDR,
1491                                (__le16 __force *)mac_addr, 3);
1492         if (!is_valid_ether_addr(mac_addr)) {
1493                 printk(KERN_WARNING "rtl8187: Invalid hwaddr! Using randomly "
1494                        "generated MAC address\n");
1495                 eth_random_addr(mac_addr);
1496         }
1497         SET_IEEE80211_PERM_ADDR(dev, mac_addr);
1498 
1499         channel = priv->channels;
1500         for (i = 0; i < 3; i++) {
1501                 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_1 + i,
1502                                   &txpwr);
1503                 (*channel++).hw_value = txpwr & 0xFF;
1504                 (*channel++).hw_value = txpwr >> 8;
1505         }
1506         for (i = 0; i < 2; i++) {
1507                 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_4 + i,
1508                                   &txpwr);
1509                 (*channel++).hw_value = txpwr & 0xFF;
1510                 (*channel++).hw_value = txpwr >> 8;
1511         }
1512 
1513         eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_BASE,
1514                           &priv->txpwr_base);
1515 
1516         reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~1;
1517         rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg | 1);
1518         /* 0 means asic B-cut, we should use SW 3 wire
1519          * bit-by-bit banging for radio. 1 means we can use
1520          * USB specific request to write radio registers */
1521         priv->asic_rev = rtl818x_ioread8(priv, (u8 *)0xFFFE) & 0x3;
1522         rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
1523         rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
1524 
1525         if (!priv->is_rtl8187b) {
1526                 u32 reg32;
1527                 reg32 = rtl818x_ioread32(priv, &priv->map->TX_CONF);
1528                 reg32 &= RTL818X_TX_CONF_HWVER_MASK;
1529                 switch (reg32) {
1530                 case RTL818X_TX_CONF_R8187vD_B:
1531                         /* Some RTL8187B devices have a USB ID of 0x8187
1532                          * detect them here */
1533                         chip_name = "RTL8187BvB(early)";
1534                         priv->is_rtl8187b = 1;
1535                         priv->hw_rev = RTL8187BvB;
1536                         break;
1537                 case RTL818X_TX_CONF_R8187vD:
1538                         chip_name = "RTL8187vD";
1539                         break;
1540                 default:
1541                         chip_name = "RTL8187vB (default)";
1542                 }
1543        } else {
1544                 /*
1545                  * Force USB request to write radio registers for 8187B, Realtek
1546                  * only uses it in their sources
1547                  */
1548                 /*if (priv->asic_rev == 0) {
1549                         printk(KERN_WARNING "rtl8187: Forcing use of USB "
1550                                "requests to write to radio registers\n");
1551                         priv->asic_rev = 1;
1552                 }*/
1553                 switch (rtl818x_ioread8(priv, (u8 *)0xFFE1)) {
1554                 case RTL818X_R8187B_B:
1555                         chip_name = "RTL8187BvB";
1556                         priv->hw_rev = RTL8187BvB;
1557                         break;
1558                 case RTL818X_R8187B_D:
1559                         chip_name = "RTL8187BvD";
1560                         priv->hw_rev = RTL8187BvD;
1561                         break;
1562                 case RTL818X_R8187B_E:
1563                         chip_name = "RTL8187BvE";
1564                         priv->hw_rev = RTL8187BvE;
1565                         break;
1566                 default:
1567                         chip_name = "RTL8187BvB (default)";
1568                         priv->hw_rev = RTL8187BvB;
1569                 }
1570         }
1571 
1572         if (!priv->is_rtl8187b) {
1573                 for (i = 0; i < 2; i++) {
1574                         eeprom_93cx6_read(&eeprom,
1575                                           RTL8187_EEPROM_TXPWR_CHAN_6 + i,
1576                                           &txpwr);
1577                         (*channel++).hw_value = txpwr & 0xFF;
1578                         (*channel++).hw_value = txpwr >> 8;
1579                 }
1580         } else {
1581                 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_6,
1582                                   &txpwr);
1583                 (*channel++).hw_value = txpwr & 0xFF;
1584 
1585                 eeprom_93cx6_read(&eeprom, 0x0A, &txpwr);
1586                 (*channel++).hw_value = txpwr & 0xFF;
1587 
1588                 eeprom_93cx6_read(&eeprom, 0x1C, &txpwr);
1589                 (*channel++).hw_value = txpwr & 0xFF;
1590                 (*channel++).hw_value = txpwr >> 8;
1591         }
1592         /* Handle the differing rfkill GPIO bit in different models */
1593         priv->rfkill_mask = RFKILL_MASK_8187_89_97;
1594         if (product_id == 0x8197 || product_id == 0x8198) {
1595                 eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_SELECT_GPIO, &reg);
1596                 if (reg & 0xFF00)
1597                         priv->rfkill_mask = RFKILL_MASK_8198;
1598         }
1599         dev->vif_data_size = sizeof(struct rtl8187_vif);
1600         dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1601                                       BIT(NL80211_IFTYPE_ADHOC) ;
1602 
1603         if ((id->driver_info == DEVICE_RTL8187) && priv->is_rtl8187b)
1604                 printk(KERN_INFO "rtl8187: inconsistency between id with OEM"
1605                        " info!\n");
1606 
1607         priv->rf = rtl8187_detect_rf(dev);
1608         dev->extra_tx_headroom = (!priv->is_rtl8187b) ?
1609                                   sizeof(struct rtl8187_tx_hdr) :
1610                                   sizeof(struct rtl8187b_tx_hdr);
1611         if (!priv->is_rtl8187b)
1612                 dev->queues = 1;
1613         else
1614                 dev->queues = 4;
1615 
1616         err = ieee80211_register_hw(dev);
1617         if (err) {
1618                 printk(KERN_ERR "rtl8187: Cannot register device\n");
1619                 goto err_free_dmabuf;
1620         }
1621         mutex_init(&priv->conf_mutex);
1622         skb_queue_head_init(&priv->b_tx_status.queue);
1623 
1624         wiphy_info(dev->wiphy, "hwaddr %pM, %s V%d + %s, rfkill mask %d\n",
1625                    mac_addr, chip_name, priv->asic_rev, priv->rf->name,
1626                    priv->rfkill_mask);
1627 
1628 #ifdef CONFIG_RTL8187_LEDS
1629         eeprom_93cx6_read(&eeprom, 0x3F, &reg);
1630         reg &= 0xFF;
1631         rtl8187_leds_init(dev, reg);
1632 #endif
1633         rtl8187_rfkill_init(dev);
1634 
1635         return 0;
1636 
1637  err_free_dmabuf:
1638         kfree(priv->io_dmabuf);
1639  err_free_dev:
1640         ieee80211_free_hw(dev);
1641         usb_set_intfdata(intf, NULL);
1642         usb_put_dev(udev);
1643         return err;
1644 }
1645 
1646 static void rtl8187_disconnect(struct usb_interface *intf)
1647 {
1648         struct ieee80211_hw *dev = usb_get_intfdata(intf);
1649         struct rtl8187_priv *priv;
1650 
1651         if (!dev)
1652                 return;
1653 
1654 #ifdef CONFIG_RTL8187_LEDS
1655         rtl8187_leds_exit(dev);
1656 #endif
1657         rtl8187_rfkill_exit(dev);
1658         ieee80211_unregister_hw(dev);
1659 
1660         priv = dev->priv;
1661         usb_reset_device(priv->udev);
1662         usb_put_dev(interface_to_usbdev(intf));
1663         kfree(priv->io_dmabuf);
1664         ieee80211_free_hw(dev);
1665 }
1666 
1667 static struct usb_driver rtl8187_driver = {
1668         .name           = KBUILD_MODNAME,
1669         .id_table       = rtl8187_table,
1670         .probe          = rtl8187_probe,
1671         .disconnect     = rtl8187_disconnect,
1672         .disable_hub_initiated_lpm = 1,
1673 };
1674 
1675 module_usb_driver(rtl8187_driver);
  评论这张
 
阅读(357)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017