OLD | NEW |
(Empty) | |
| 1 |
| 2 #include <linux/vmalloc.h> |
| 3 #include <linux/highmem.h> |
| 4 #include "ath9k.h" |
| 5 |
| 6 static int ath9k_debugfs_open(struct inode *inode, struct file *file) |
| 7 { |
| 8 file->private_data = inode->i_private; |
| 9 return 0; |
| 10 } |
| 11 |
| 12 static struct page *pktlog_virt_to_logical(void *addr) |
| 13 { |
| 14 struct page *page; |
| 15 unsigned long vpage = 0UL; |
| 16 |
| 17 page = vmalloc_to_page(addr); |
| 18 if (page) { |
| 19 vpage = (unsigned long) page_address(page); |
| 20 vpage |= ((unsigned long) addr & (PAGE_SIZE - 1)); |
| 21 } |
| 22 return virt_to_page((void *) vpage); |
| 23 } |
| 24 |
| 25 static void ath_pktlog_release(struct ath_pktlog *pktlog) |
| 26 { |
| 27 unsigned long page_cnt, vaddr; |
| 28 struct page *page; |
| 29 |
| 30 page_cnt = |
| 31 ((sizeof(*(pktlog->pktlog_buf)) + |
| 32 pktlog->pktlog_buf_size) / PAGE_SIZE) + 1; |
| 33 |
| 34 for (vaddr = (unsigned long) (pktlog->pktlog_buf); vaddr < |
| 35 (unsigned long) (pktlog->pktlog_buf) + |
| 36 (page_cnt * PAGE_SIZE); |
| 37 vaddr += PAGE_SIZE) { |
| 38 page = pktlog_virt_to_logical((void *) vaddr); |
| 39 clear_bit(PG_reserved, &page->flags); |
| 40 } |
| 41 |
| 42 vfree(pktlog->pktlog_buf); |
| 43 pktlog->pktlog_buf = NULL; |
| 44 } |
| 45 |
| 46 static int ath_alloc_pktlog_buf(struct ath_softc *sc) |
| 47 { |
| 48 u32 page_cnt; |
| 49 unsigned long vaddr; |
| 50 struct page *page; |
| 51 struct ath_pktlog *pktlog = &sc->pktlog.pktlog; |
| 52 |
| 53 if (pktlog->pktlog_buf_size == 0) |
| 54 return -EINVAL; |
| 55 |
| 56 page_cnt = (sizeof(*(pktlog->pktlog_buf)) + |
| 57 pktlog->pktlog_buf_size) / PAGE_SIZE; |
| 58 |
| 59 pktlog->pktlog_buf = vmalloc((page_cnt + 2) * PAGE_SIZE); |
| 60 if (pktlog->pktlog_buf == NULL) { |
| 61 printk(KERN_ERR "Failed to allocate memory for pktlog"); |
| 62 return -ENOMEM; |
| 63 } |
| 64 |
| 65 pktlog->pktlog_buf = (struct ath_pktlog_buf *) |
| 66 (((unsigned long) |
| 67 (pktlog->pktlog_buf) |
| 68 + PAGE_SIZE - 1) & PAGE_MASK); |
| 69 |
| 70 for (vaddr = (unsigned long) (pktlog->pktlog_buf); |
| 71 vaddr < ((unsigned long) (pktlog->pktlog_buf) |
| 72 + (page_cnt * PAGE_SIZE)); vaddr += PAGE_SIZE) { |
| 73 page = pktlog_virt_to_logical((void *)vaddr); |
| 74 set_bit(PG_reserved, &page->flags); |
| 75 } |
| 76 |
| 77 return 0; |
| 78 } |
| 79 |
| 80 static void ath_init_pktlog_buf(struct ath_pktlog *pktlog) |
| 81 { |
| 82 pktlog->pktlog_buf->bufhdr.magic_num = PKTLOG_MAGIC_NUM; |
| 83 pktlog->pktlog_buf->bufhdr.version = CUR_PKTLOG_VER; |
| 84 pktlog->pktlog_buf->rd_offset = -1; |
| 85 pktlog->pktlog_buf->wr_offset = 0; |
| 86 if (pktlog->pktlog_filter == 0) |
| 87 pktlog->pktlog_filter = ATH_PKTLOG_FILTER_DEFAULT; |
| 88 } |
| 89 |
| 90 static char *ath_pktlog_getbuf(struct ath_pktlog *pl_info, |
| 91 u16 log_type, size_t log_size, |
| 92 u32 flags) |
| 93 { |
| 94 struct ath_pktlog_buf *log_buf; |
| 95 struct ath_pktlog_hdr *log_hdr; |
| 96 int32_t cur_wr_offset, buf_size; |
| 97 char *log_ptr; |
| 98 |
| 99 log_buf = pl_info->pktlog_buf; |
| 100 buf_size = pl_info->pktlog_buf_size; |
| 101 |
| 102 spin_lock_bh(&pl_info->pktlog_lock); |
| 103 cur_wr_offset = log_buf->wr_offset; |
| 104 /* Move read offset to the next entry if there is a buffer overlap */ |
| 105 if (log_buf->rd_offset >= 0) { |
| 106 if ((cur_wr_offset <= log_buf->rd_offset) |
| 107 && (cur_wr_offset + |
| 108 sizeof(struct ath_pktlog_hdr)) > |
| 109 log_buf->rd_offset) |
| 110 PKTLOG_MOV_RD_IDX(log_buf->rd_offset, log_buf, |
| 111 buf_size); |
| 112 } else { |
| 113 log_buf->rd_offset = cur_wr_offset; |
| 114 } |
| 115 |
| 116 log_hdr = |
| 117 (struct ath_pktlog_hdr *) (log_buf->log_data + cur_wr_offset); |
| 118 log_hdr->log_type = log_type; |
| 119 log_hdr->flags = flags; |
| 120 log_hdr->timestamp = jiffies; |
| 121 log_hdr->size = (u16) log_size; |
| 122 |
| 123 cur_wr_offset += sizeof(*log_hdr); |
| 124 |
| 125 if ((buf_size - cur_wr_offset) < log_size) { |
| 126 while ((cur_wr_offset <= log_buf->rd_offset) |
| 127 && (log_buf->rd_offset < buf_size)) |
| 128 PKTLOG_MOV_RD_IDX(log_buf->rd_offset, log_buf, |
| 129 buf_size); |
| 130 cur_wr_offset = 0; |
| 131 } |
| 132 |
| 133 while ((cur_wr_offset <= log_buf->rd_offset) |
| 134 && (cur_wr_offset + log_size) > log_buf->rd_offset) |
| 135 PKTLOG_MOV_RD_IDX(log_buf->rd_offset, log_buf, buf_size); |
| 136 |
| 137 log_ptr = &(log_buf->log_data[cur_wr_offset]); |
| 138 |
| 139 cur_wr_offset += log_hdr->size; |
| 140 |
| 141 log_buf->wr_offset = |
| 142 ((buf_size - cur_wr_offset) >= |
| 143 sizeof(struct ath_pktlog_hdr)) ? cur_wr_offset : 0; |
| 144 spin_unlock_bh(&pl_info->pktlog_lock); |
| 145 |
| 146 return log_ptr; |
| 147 } |
| 148 |
| 149 static void ath9k_hw_get_descinfo(struct ath_hw *ah, struct ath_desc_info *desc_
info) |
| 150 { |
| 151 desc_info->txctl_numwords = TXCTL_NUMWORDS(ah); |
| 152 desc_info->txctl_offset = TXCTL_OFFSET(ah); |
| 153 desc_info->txstatus_numwords = TXSTATUS_NUMWORDS(ah); |
| 154 desc_info->txstatus_offset = TXSTATUS_OFFSET(ah); |
| 155 |
| 156 desc_info->rxctl_numwords = RXCTL_NUMWORDS(ah); |
| 157 desc_info->rxctl_offset = RXCTL_OFFSET(ah); |
| 158 desc_info->rxstatus_numwords = RXSTATUS_NUMWORDS(ah); |
| 159 desc_info->rxstatus_offset = RXSTATUS_OFFSET(ah); |
| 160 } |
| 161 |
| 162 static int pktlog_pgfault(struct vm_area_struct *vma, struct vm_fault *vmf) |
| 163 { |
| 164 unsigned long address = (unsigned long) vmf->virtual_address; |
| 165 |
| 166 if (address == 0UL) |
| 167 return VM_FAULT_NOPAGE; |
| 168 |
| 169 if (vmf->pgoff > vma->vm_end) |
| 170 return VM_FAULT_SIGBUS; |
| 171 |
| 172 get_page(virt_to_page(address)); |
| 173 vmf->page = virt_to_page(address); |
| 174 return VM_FAULT_MINOR; |
| 175 } |
| 176 |
| 177 static struct vm_operations_struct pktlog_vmops = { |
| 178 .fault = pktlog_pgfault |
| 179 }; |
| 180 |
| 181 static int ath_pktlog_mmap(struct file *file, struct vm_area_struct *vma) |
| 182 { |
| 183 struct ath_softc *sc = file->private_data; |
| 184 |
| 185 /* entire buffer should be mapped */ |
| 186 if (vma->vm_pgoff != 0) |
| 187 return -EINVAL; |
| 188 |
| 189 if (!sc->pktlog.pktlog.pktlog_buf) { |
| 190 printk(KERN_ERR "Can't allocate pktlog buf"); |
| 191 return -ENOMEM; |
| 192 } |
| 193 |
| 194 vma->vm_flags |= VM_LOCKED; |
| 195 vma->vm_ops = &pktlog_vmops; |
| 196 |
| 197 return 0; |
| 198 } |
| 199 |
| 200 static ssize_t ath_pktlog_read(struct file *file, char __user *userbuf, |
| 201 size_t count, loff_t *ppos) |
| 202 { |
| 203 size_t bufhdr_size; |
| 204 size_t nbytes = 0, ret_val = 0; |
| 205 int rem_len; |
| 206 int start_offset, end_offset; |
| 207 int fold_offset, ppos_data, cur_rd_offset; |
| 208 struct ath_softc *sc = file->private_data; |
| 209 struct ath_pktlog *pktlog_info = &sc->pktlog.pktlog; |
| 210 struct ath_pktlog_buf *log_buf = pktlog_info->pktlog_buf; |
| 211 |
| 212 if (log_buf == NULL) |
| 213 return 0; |
| 214 |
| 215 bufhdr_size = sizeof(log_buf->bufhdr); |
| 216 |
| 217 /* copy valid log entries from circular buffer into user space */ |
| 218 rem_len = count; |
| 219 |
| 220 nbytes = 0; |
| 221 |
| 222 if (*ppos < bufhdr_size) { |
| 223 nbytes = min((int) (bufhdr_size - *ppos), rem_len); |
| 224 if (copy_to_user(userbuf, |
| 225 ((char *) &log_buf->bufhdr) + *ppos, nbytes)) |
| 226 return -EFAULT; |
| 227 rem_len -= nbytes; |
| 228 ret_val += nbytes; |
| 229 } |
| 230 |
| 231 start_offset = log_buf->rd_offset; |
| 232 |
| 233 if ((rem_len == 0) || (start_offset < 0)) |
| 234 goto read_done; |
| 235 |
| 236 fold_offset = -1; |
| 237 cur_rd_offset = start_offset; |
| 238 |
| 239 /* Find the last offset and fold-offset if the buffer is folded */ |
| 240 do { |
| 241 struct ath_pktlog_hdr *log_hdr; |
| 242 int log_data_offset; |
| 243 |
| 244 log_hdr = |
| 245 (struct ath_pktlog_hdr *) (log_buf->log_data + |
| 246 cur_rd_offset); |
| 247 |
| 248 log_data_offset = cur_rd_offset + sizeof(struct ath_pktlog_hdr); |
| 249 |
| 250 if ((fold_offset == -1) |
| 251 && ((pktlog_info->pktlog_buf_size - |
| 252 log_data_offset) <= log_hdr->size)) |
| 253 fold_offset = log_data_offset - 1; |
| 254 |
| 255 PKTLOG_MOV_RD_IDX(cur_rd_offset, log_buf, |
| 256 pktlog_info->pktlog_buf_size); |
| 257 |
| 258 if ((fold_offset == -1) && (cur_rd_offset == 0) |
| 259 && (cur_rd_offset != log_buf->wr_offset)) |
| 260 fold_offset = log_data_offset + log_hdr->size - 1; |
| 261 |
| 262 end_offset = log_data_offset + log_hdr->size - 1; |
| 263 } while (cur_rd_offset != log_buf->wr_offset); |
| 264 |
| 265 ppos_data = *ppos + ret_val - bufhdr_size + start_offset; |
| 266 |
| 267 if (fold_offset == -1) { |
| 268 if (ppos_data > end_offset) |
| 269 goto read_done; |
| 270 |
| 271 nbytes = min(rem_len, end_offset - ppos_data + 1); |
| 272 if (copy_to_user(userbuf + ret_val, |
| 273 log_buf->log_data + ppos_data, nbytes)) |
| 274 return -EFAULT; |
| 275 ret_val += nbytes; |
| 276 rem_len -= nbytes; |
| 277 } else { |
| 278 if (ppos_data <= fold_offset) { |
| 279 nbytes = min(rem_len, fold_offset - ppos_data + 1); |
| 280 if (copy_to_user(userbuf + ret_val, |
| 281 log_buf->log_data + ppos_data, |
| 282 nbytes)) |
| 283 return -EFAULT; |
| 284 ret_val += nbytes; |
| 285 rem_len -= nbytes; |
| 286 } |
| 287 |
| 288 if (rem_len == 0) |
| 289 goto read_done; |
| 290 |
| 291 ppos_data = |
| 292 *ppos + ret_val - (bufhdr_size + |
| 293 (fold_offset - start_offset + 1)); |
| 294 |
| 295 if (ppos_data <= end_offset) { |
| 296 nbytes = min(rem_len, end_offset - ppos_data + 1); |
| 297 if (copy_to_user(userbuf + ret_val, log_buf->log_data |
| 298 + ppos_data, |
| 299 nbytes)) |
| 300 return -EFAULT; |
| 301 ret_val += nbytes; |
| 302 rem_len -= nbytes; |
| 303 } |
| 304 } |
| 305 |
| 306 read_done: |
| 307 *ppos += ret_val; |
| 308 |
| 309 return ret_val; |
| 310 } |
| 311 |
| 312 static const struct file_operations fops_pktlog_dump = { |
| 313 .read = ath_pktlog_read, |
| 314 .mmap = ath_pktlog_mmap, |
| 315 .open = ath9k_debugfs_open |
| 316 }; |
| 317 |
| 318 static ssize_t write_pktlog_start(struct file *file, const char __user *ubuf, |
| 319 size_t count, loff_t *ppos) |
| 320 { |
| 321 struct ath_softc *sc = file->private_data; |
| 322 struct ath_pktlog *pktlog = &sc->pktlog.pktlog; |
| 323 char buf[32]; |
| 324 int buf_size; |
| 325 int start_pktlog, err; |
| 326 |
| 327 buf_size = min(count, sizeof(buf) - 1); |
| 328 if (copy_from_user(buf, ubuf, buf_size)) |
| 329 return -EFAULT; |
| 330 |
| 331 sscanf(buf, "%d", &start_pktlog); |
| 332 if (start_pktlog) { |
| 333 if (pktlog->pktlog_buf != NULL) |
| 334 ath_pktlog_release(pktlog); |
| 335 |
| 336 err = ath_alloc_pktlog_buf(sc); |
| 337 if (err != 0) |
| 338 return err; |
| 339 |
| 340 ath_init_pktlog_buf(pktlog); |
| 341 pktlog->pktlog_buf->rd_offset = -1; |
| 342 pktlog->pktlog_buf->wr_offset = 0; |
| 343 sc->is_pkt_logging = 1; |
| 344 } else { |
| 345 sc->is_pkt_logging = 0; |
| 346 } |
| 347 |
| 348 sc->sc_ah->is_pkt_logging = sc->is_pkt_logging; |
| 349 return count; |
| 350 } |
| 351 |
| 352 static ssize_t read_pktlog_start(struct file *file, char __user *ubuf, |
| 353 size_t count, loff_t *ppos) |
| 354 { |
| 355 char buf[32]; |
| 356 struct ath_softc *sc = file->private_data; |
| 357 int len = 0; |
| 358 |
| 359 len = scnprintf(buf, sizeof(buf) - len, "%d", sc->is_pkt_logging); |
| 360 return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 361 } |
| 362 |
| 363 static const struct file_operations fops_pktlog_start = { |
| 364 .read = read_pktlog_start, |
| 365 .write = write_pktlog_start, |
| 366 .open = ath9k_debugfs_open |
| 367 }; |
| 368 |
| 369 static ssize_t pktlog_size_write(struct file *file, const char __user *ubuf, |
| 370 size_t count, loff_t *ppos) |
| 371 { |
| 372 struct ath_softc *sc = file->private_data; |
| 373 char buf[32]; |
| 374 u32 pktlog_size; |
| 375 int buf_size; |
| 376 |
| 377 buf_size = min(count, sizeof(buf) - 1); |
| 378 if (copy_from_user(buf, ubuf, buf_size)) |
| 379 return -EFAULT; |
| 380 |
| 381 sscanf(buf, "%d", &pktlog_size); |
| 382 |
| 383 if (pktlog_size == sc->pktlog.pktlog.pktlog_buf_size) |
| 384 return count; |
| 385 |
| 386 if (sc->is_pkt_logging) { |
| 387 printk(KERN_DEBUG "Stop packet logging before" |
| 388 " changing the pktlog size \n"); |
| 389 return -EINVAL; |
| 390 } |
| 391 |
| 392 sc->pktlog.pktlog.pktlog_buf_size = pktlog_size; |
| 393 |
| 394 return count; |
| 395 } |
| 396 |
| 397 static ssize_t pktlog_size_read(struct file *file, char __user *ubuf, |
| 398 size_t count, loff_t *ppos) |
| 399 { |
| 400 char buf[32]; |
| 401 struct ath_softc *sc = file->private_data; |
| 402 int len = 0; |
| 403 |
| 404 len = scnprintf(buf, sizeof(buf) - len, "%ul", |
| 405 sc->pktlog.pktlog.pktlog_buf_size); |
| 406 return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 407 } |
| 408 |
| 409 static const struct file_operations fops_pktlog_size = { |
| 410 .read = pktlog_size_read, |
| 411 .write = pktlog_size_write, |
| 412 .open = ath9k_debugfs_open |
| 413 }; |
| 414 |
| 415 static ssize_t pktlog_filter_write(struct file *file, const char __user *ubuf, |
| 416 size_t count, loff_t *ppos) |
| 417 { |
| 418 char buf[32]; |
| 419 struct ath_softc *sc = file->private_data; |
| 420 u32 filter; |
| 421 int buf_count; |
| 422 |
| 423 buf_count = min(count, sizeof(buf) - 1); |
| 424 if (copy_from_user(buf, ubuf, buf_count)) |
| 425 return -EFAULT; |
| 426 |
| 427 if (sscanf(buf, "%x", &filter)) |
| 428 sc->pktlog.pktlog.pktlog_filter = filter; |
| 429 else |
| 430 sc->pktlog.pktlog.pktlog_filter = 0; |
| 431 |
| 432 return count; |
| 433 } |
| 434 |
| 435 static ssize_t pktlog_filter_read(struct file *file, char __user *ubuf, |
| 436 size_t count, loff_t *ppos) |
| 437 { |
| 438 char buf[32]; |
| 439 struct ath_softc *sc = file->private_data; |
| 440 int len = 0; |
| 441 |
| 442 len = scnprintf(buf, sizeof(buf) - len, "%ul", |
| 443 sc->pktlog.pktlog.pktlog_filter); |
| 444 |
| 445 return simple_read_from_buffer(ubuf, count, ppos, buf, len); |
| 446 } |
| 447 |
| 448 static const struct file_operations fops_pktlog_filter = { |
| 449 .read = pktlog_filter_read, |
| 450 .write = pktlog_filter_write, |
| 451 .open = ath9k_debugfs_open |
| 452 }; |
| 453 |
| 454 void ath_pktlog_txctl(struct ath_softc *sc, struct ath_buf *bf) |
| 455 { |
| 456 struct ath_pktlog_txctl *tx_log; |
| 457 struct ath_pktlog *pl_info; |
| 458 struct ieee80211_hdr *hdr; |
| 459 struct ath_desc_info desc_info; |
| 460 int i; |
| 461 u32 *ds_words, flags = 0; |
| 462 |
| 463 pl_info = &sc->pktlog.pktlog; |
| 464 |
| 465 if ((pl_info->pktlog_filter & ATH_PKTLOG_TX) == 0 || |
| 466 bf->bf_mpdu == NULL || !sc->is_pkt_logging) |
| 467 return; |
| 468 |
| 469 flags |= (((sc->sc_ah->hw_version.macRev << |
| 470 PHFLAGS_MACREV_SFT) & PHFLAGS_MACREV_MASK) | |
| 471 ((sc->sc_ah->hw_version.macVersion << PHFLAGS_MACVERSION
_SFT) |
| 472 & PHFLAGS_MACVERSION_MASK)); |
| 473 |
| 474 tx_log = (struct ath_pktlog_txctl *)ath_pktlog_getbuf(pl_info, |
| 475 PKTLOG_TYPE_TXCTL, sizeof(*tx_log), flags); |
| 476 |
| 477 memset(tx_log, 0, sizeof(*tx_log)); |
| 478 |
| 479 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data; |
| 480 tx_log->framectrl = hdr->frame_control; |
| 481 tx_log->seqctrl = hdr->seq_ctrl; |
| 482 |
| 483 if (ieee80211_has_tods(tx_log->framectrl)) { |
| 484 tx_log->bssid_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 485 (hdr->addr1[ETH_ALEN - 1]); |
| 486 tx_log->sa_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 487 (hdr->addr2[ETH_ALEN - 1]); |
| 488 tx_log->da_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 489 (hdr->addr3[ETH_ALEN - 1]); |
| 490 } else if (ieee80211_has_fromds(tx_log->framectrl)) { |
| 491 tx_log->bssid_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 492 (hdr->addr2[ETH_ALEN - 1]); |
| 493 tx_log->sa_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 494 (hdr->addr3[ETH_ALEN - 1]); |
| 495 tx_log->da_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 496 (hdr->addr1[ETH_ALEN - 1]); |
| 497 } else { |
| 498 tx_log->bssid_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 499 (hdr->addr3[ETH_ALEN - 1]); |
| 500 tx_log->sa_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 501 (hdr->addr2[ETH_ALEN - 1]); |
| 502 tx_log->da_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 503 (hdr->addr1[ETH_ALEN - 1]); |
| 504 } |
| 505 |
| 506 ath9k_hw_get_descinfo(sc->sc_ah, &desc_info); |
| 507 |
| 508 ds_words = (u32 *)(bf->bf_desc) + desc_info.txctl_offset; |
| 509 for (i = 0; i < desc_info.txctl_numwords; i++) |
| 510 tx_log->txdesc_ctl[i] = ds_words[i]; |
| 511 } |
| 512 |
| 513 void ath_pktlog_txstatus(struct ath_softc *sc, void *ds) |
| 514 { |
| 515 struct ath_pktlog_txstatus *tx_log; |
| 516 struct ath_pktlog *pl_info; |
| 517 struct ath_desc_info desc_info; |
| 518 int i; |
| 519 u32 *ds_words, flags = 0; |
| 520 |
| 521 pl_info = &sc->pktlog.pktlog; |
| 522 |
| 523 if ((pl_info->pktlog_filter & ATH_PKTLOG_TX) == 0 || |
| 524 !sc->is_pkt_logging) |
| 525 return; |
| 526 |
| 527 flags |= (((sc->sc_ah->hw_version.macRev << |
| 528 PHFLAGS_MACREV_SFT) & PHFLAGS_MACREV_MASK) | |
| 529 ((sc->sc_ah->hw_version.macVersion << PHFLAGS_MACVERSION_SFT) |
| 530 & PHFLAGS_MACVERSION_MASK)); |
| 531 tx_log = (struct ath_pktlog_txstatus *)ath_pktlog_getbuf(pl_info, |
| 532 PKTLOG_TYPE_TXSTATUS, sizeof(*tx_log), flags); |
| 533 |
| 534 memset(tx_log, 0, sizeof(*tx_log)); |
| 535 |
| 536 ath9k_hw_get_descinfo(sc->sc_ah, &desc_info); |
| 537 |
| 538 ds_words = (u32 *)(ds) + desc_info.txstatus_offset; |
| 539 |
| 540 for (i = 0; i < desc_info.txstatus_numwords; i++) |
| 541 tx_log->txdesc_status[i] = ds_words[i]; |
| 542 } |
| 543 |
| 544 void ath_pktlog_rx(struct ath_softc *sc, void *desc, struct sk_buff *skb) |
| 545 { |
| 546 struct ath_pktlog_rx *rx_log; |
| 547 struct ath_pktlog *pl_info; |
| 548 struct ieee80211_hdr *hdr; |
| 549 struct ath_desc_info desc_info; |
| 550 int i; |
| 551 u32 *ds_words, flags = 0; |
| 552 |
| 553 pl_info = &sc->pktlog.pktlog; |
| 554 |
| 555 if ((pl_info->pktlog_filter & ATH_PKTLOG_RX) == 0 || |
| 556 !sc->is_pkt_logging) |
| 557 return; |
| 558 |
| 559 flags |= (((sc->sc_ah->hw_version.macRev << |
| 560 PHFLAGS_MACREV_SFT) & PHFLAGS_MACREV_MASK) | |
| 561 ((sc->sc_ah->hw_version.macVersion << |
| 562 PHFLAGS_MACVERSION_SFT) & PHFLAGS_MACVERSION_MASK)); |
| 563 |
| 564 rx_log = (struct ath_pktlog_rx *)ath_pktlog_getbuf(pl_info, PKTLOG_TYPE_
RX, |
| 565 sizeof(*rx_log), flags); |
| 566 |
| 567 memset(rx_log, 0, sizeof(*rx_log)); |
| 568 |
| 569 if (skb->len > sizeof(struct ieee80211_hdr)) { |
| 570 hdr = (struct ieee80211_hdr *) skb->data; |
| 571 rx_log->framectrl = hdr->frame_control; |
| 572 rx_log->seqctrl = hdr->seq_ctrl; |
| 573 |
| 574 if (ieee80211_has_tods(rx_log->framectrl)) { |
| 575 rx_log->bssid_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 576 (hdr->addr1[ETH_ALEN - 1]); |
| 577 rx_log->sa_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 578 (hdr->addr2[ETH_ALEN - 1]); |
| 579 rx_log->da_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 580 (hdr->addr3[ETH_ALEN - 1]); |
| 581 } else if (ieee80211_has_fromds(rx_log->framectrl)) { |
| 582 rx_log->bssid_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 583 (hdr->addr2[ETH_ALEN - 1]); |
| 584 rx_log->sa_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 585 (hdr->addr3[ETH_ALEN - 1]); |
| 586 rx_log->da_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 587 (hdr->addr1[ETH_ALEN - 1]); |
| 588 } else { |
| 589 rx_log->bssid_tail = (hdr->addr3[ETH_ALEN - 2] << 8) | |
| 590 (hdr->addr3[ETH_ALEN - 1]); |
| 591 rx_log->sa_tail = (hdr->addr2[ETH_ALEN - 2] << 8) | |
| 592 (hdr->addr2[ETH_ALEN - 1]); |
| 593 rx_log->da_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 594 (hdr->addr1[ETH_ALEN - 1]); |
| 595 } |
| 596 } else { |
| 597 hdr = (struct ieee80211_hdr *) skb->data; |
| 598 |
| 599 if (ieee80211_is_ctl(hdr->frame_control)) { |
| 600 rx_log->framectrl = hdr->frame_control; |
| 601 rx_log->da_tail = (hdr->addr1[ETH_ALEN - 2] << 8) | |
| 602 (hdr->addr1[ETH_ALEN - 1]); |
| 603 if (skb->len < sizeof(struct ieee80211_rts)) { |
| 604 rx_log->sa_tail = 0; |
| 605 } else { |
| 606 rx_log->sa_tail = (hdr->addr2[ETH_ALEN - 2] |
| 607 << 8) | |
| 608 (hdr->addr2[ETH_ALEN - 1]); |
| 609 } |
| 610 } else { |
| 611 rx_log->framectrl = 0xFFFF; |
| 612 rx_log->da_tail = 0; |
| 613 rx_log->sa_tail = 0; |
| 614 } |
| 615 |
| 616 rx_log->seqctrl = 0; |
| 617 rx_log->bssid_tail = 0; |
| 618 } |
| 619 |
| 620 ath9k_hw_get_descinfo(sc->sc_ah, &desc_info); |
| 621 |
| 622 ds_words = (u32 *)(desc) + desc_info.rxstatus_offset; |
| 623 |
| 624 for (i = 0; i < desc_info.rxstatus_numwords; i++) |
| 625 rx_log->rxdesc_status[i] = ds_words[i]; |
| 626 } |
| 627 |
| 628 void ath9k_pktlog_rc(struct ath_softc *sc, struct ath_rate_priv *ath_rc_priv, |
| 629 int8_t ratecode, u8 rate, int8_t is_probing, u16 ac) |
| 630 { |
| 631 struct ath_pktlog_rcfind *rcf_log; |
| 632 struct ath_pktlog *pl_info; |
| 633 u32 flags = 0; |
| 634 |
| 635 pl_info = &sc->pktlog.pktlog; |
| 636 |
| 637 if ((pl_info->pktlog_filter & ATH_PKTLOG_RCFIND) == 0 || |
| 638 !sc->is_pkt_logging) |
| 639 return; |
| 640 |
| 641 flags |= (((sc->sc_ah->hw_version.macRev << |
| 642 PHFLAGS_MACREV_SFT) & PHFLAGS_MACREV_MASK) | |
| 643 ((sc->sc_ah->hw_version.macVersion << |
| 644 PHFLAGS_MACVERSION_SFT) & PHFLAGS_MACVERSION_MASK)); |
| 645 rcf_log = (struct ath_pktlog_rcfind *)ath_pktlog_getbuf(pl_info, |
| 646 PKTLOG_TYPE_RCFIND, sizeof(*rcf_log), flags); |
| 647 |
| 648 rcf_log->rate = rate; |
| 649 rcf_log->rateCode = ratecode; |
| 650 rcf_log->rcProbeRate = is_probing ? ath_rc_priv->probe_rate : 0; |
| 651 rcf_log->isProbing = is_probing; |
| 652 rcf_log->ac = ac; |
| 653 rcf_log->rcRateMax = ath_rc_priv->rate_max_phy; |
| 654 rcf_log->rcRateTableSize = ath_rc_priv->rate_table_size; |
| 655 } |
| 656 |
| 657 void ath9k_pktlog_rcupdate(struct ath_softc *sc, struct ath_rate_priv *ath_rc_pr
iv, u8 tx_rate, |
| 658 u8 rate_code, u8 xretries, u8 retries, int8_t rssi, u
16 ac) |
| 659 { |
| 660 struct ath_pktlog_rcupdate *rcu_log; |
| 661 struct ath_pktlog *pl_info; |
| 662 int i; |
| 663 u32 flags = 0; |
| 664 |
| 665 pl_info = &sc->pktlog.pktlog; |
| 666 |
| 667 if ((pl_info->pktlog_filter & ATH_PKTLOG_RCUPDATE) == 0 || |
| 668 !sc->is_pkt_logging) |
| 669 return; |
| 670 |
| 671 flags |= (((sc->sc_ah->hw_version.macRev << |
| 672 PHFLAGS_MACREV_SFT) & PHFLAGS_MACREV_MASK) | |
| 673 ((sc->sc_ah->hw_version.macVersion << |
| 674 PHFLAGS_MACVERSION_SFT) & PHFLAGS_MACVERSION_MASK)); |
| 675 rcu_log = (struct ath_pktlog_rcupdate *)ath_pktlog_getbuf(pl_info, |
| 676 PKTLOG_TYPE_RCUPDATE, |
| 677 sizeof(*rcu_log), flags); |
| 678 |
| 679 memset(rcu_log, 0, sizeof(*rcu_log)); |
| 680 |
| 681 rcu_log->txRate = tx_rate; |
| 682 rcu_log->rateCode = rate_code; |
| 683 rcu_log->Xretries = xretries; |
| 684 rcu_log->retries = retries; |
| 685 rcu_log->rssiAck = rssi; |
| 686 rcu_log->ac = ac; |
| 687 rcu_log->rcProbeRate = ath_rc_priv->probe_rate; |
| 688 rcu_log->rcRateMax = ath_rc_priv->rate_max_phy; |
| 689 |
| 690 for (i = 0; i < RATE_TABLE_SIZE; i++) { |
| 691 rcu_log->rcPer[i] = ath_rc_priv->per[i]; |
| 692 } |
| 693 } |
| 694 |
| 695 void ath9k_pktlog_txcomplete(struct ath_softc *sc, struct list_head *bf_head, |
| 696 struct ath_buf *bf, struct ath_buf *bf_last) |
| 697 { |
| 698 struct log_tx ; |
| 699 struct ath_buf *tbf; |
| 700 |
| 701 list_for_each_entry(tbf, bf_head, list) |
| 702 ath_pktlog_txctl(sc, tbf); |
| 703 |
| 704 if (bf->bf_next == NULL && bf_last->bf_stale) |
| 705 ath_pktlog_txctl(sc, bf_last); |
| 706 } |
| 707 |
| 708 void ath9k_pktlog_txctrl(struct ath_softc *sc, struct list_head *bf_head, struct
ath_buf *lastbf) |
| 709 { |
| 710 struct log_tx ; |
| 711 struct ath_buf *tbf; |
| 712 |
| 713 list_for_each_entry(tbf, bf_head, list) |
| 714 ath_pktlog_txctl(sc, tbf); |
| 715 |
| 716 /* log the last descriptor. */ |
| 717 ath_pktlog_txctl(sc, lastbf); |
| 718 } |
| 719 |
| 720 static void pktlog_init(struct ath_softc *sc) |
| 721 { |
| 722 spin_lock_init(&sc->pktlog.pktlog.pktlog_lock); |
| 723 sc->pktlog.pktlog.pktlog_buf_size = ATH_DEBUGFS_PKTLOG_SIZE_DEFAULT; |
| 724 sc->pktlog.pktlog.pktlog_buf = NULL; |
| 725 sc->pktlog.pktlog.pktlog_filter = 0; |
| 726 } |
| 727 |
| 728 int ath9k_init_pktlog(struct ath_softc *sc) |
| 729 { |
| 730 sc->pktlog.debugfs_pktlog = debugfs_create_dir("pktlog", |
| 731 sc->debug.debugfs_phy); |
| 732 if (!sc->pktlog.debugfs_pktlog) |
| 733 goto err; |
| 734 |
| 735 sc->pktlog.pktlog_start = debugfs_create_file("pktlog_start", |
| 736 S_IRUGO | S_IWUSR, |
| 737 sc->pktlog.debugfs_pktlog, |
| 738 sc, &fops_pktlog_start); |
| 739 if (!sc->pktlog.pktlog_start) |
| 740 goto err; |
| 741 |
| 742 sc->pktlog.pktlog_size = debugfs_create_file("pktlog_size", |
| 743 S_IRUGO | S_IWUSR, |
| 744 sc->pktlog.debugfs_pktlog, |
| 745 sc, &fops_pktlog_size); |
| 746 if (!sc->pktlog.pktlog_size) |
| 747 goto err; |
| 748 |
| 749 sc->pktlog.pktlog_filter = debugfs_create_file("pktlog_filter", |
| 750 S_IRUGO | S_IWUSR, |
| 751 sc->pktlog.debugfs_pktlog, |
| 752 sc, &fops_pktlog_filter); |
| 753 if (!sc->pktlog.pktlog_filter) |
| 754 goto err; |
| 755 |
| 756 sc->pktlog.pktlog_dump = debugfs_create_file("pktlog_dump", |
| 757 S_IRUGO, |
| 758 sc->pktlog.debugfs_pktlog, |
| 759 sc, &fops_pktlog_dump); |
| 760 if (!sc->pktlog.pktlog_dump) |
| 761 goto err; |
| 762 |
| 763 pktlog_init(sc); |
| 764 |
| 765 return 0; |
| 766 |
| 767 err: |
| 768 return -ENOMEM; |
| 769 } |
| 770 |
| 771 void ath9k_deinit_pktlog(struct ath_softc *sc) |
| 772 { |
| 773 struct ath_pktlog *pktlog = &sc->pktlog.pktlog; |
| 774 |
| 775 if (pktlog->pktlog_buf != NULL) |
| 776 ath_pktlog_release(pktlog); |
| 777 |
| 778 debugfs_remove(sc->pktlog.pktlog_start); |
| 779 debugfs_remove(sc->pktlog.pktlog_size); |
| 780 debugfs_remove(sc->pktlog.pktlog_filter); |
| 781 debugfs_remove(sc->pktlog.pktlog_dump); |
| 782 debugfs_remove(sc->pktlog.debugfs_pktlog); |
| 783 } |
OLD | NEW |