qla_attr.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. static int qla24xx_vport_disable(struct fc_vport *, bool);
  12. /* SYSFS attributes --------------------------------------------------------- */
  13. static ssize_t
  14. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  15. struct bin_attribute *bin_attr,
  16. char *buf, loff_t off, size_t count)
  17. {
  18. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  19. struct device, kobj)));
  20. struct qla_hw_data *ha = vha->hw;
  21. if (ha->fw_dump_reading == 0)
  22. return 0;
  23. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  24. ha->fw_dump_len);
  25. }
  26. static ssize_t
  27. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  28. struct bin_attribute *bin_attr,
  29. char *buf, loff_t off, size_t count)
  30. {
  31. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  32. struct device, kobj)));
  33. struct qla_hw_data *ha = vha->hw;
  34. int reading;
  35. if (off != 0)
  36. return (0);
  37. reading = simple_strtol(buf, NULL, 10);
  38. switch (reading) {
  39. case 0:
  40. if (!ha->fw_dump_reading)
  41. break;
  42. qla_printk(KERN_INFO, ha,
  43. "Firmware dump cleared on (%ld).\n", vha->host_no);
  44. ha->fw_dump_reading = 0;
  45. ha->fw_dumped = 0;
  46. break;
  47. case 1:
  48. if (ha->fw_dumped && !ha->fw_dump_reading) {
  49. ha->fw_dump_reading = 1;
  50. qla_printk(KERN_INFO, ha,
  51. "Raw firmware dump ready for read on (%ld).\n",
  52. vha->host_no);
  53. }
  54. break;
  55. case 2:
  56. qla2x00_alloc_fw_dump(vha);
  57. break;
  58. case 3:
  59. qla2x00_system_error(vha);
  60. break;
  61. }
  62. return (count);
  63. }
  64. static struct bin_attribute sysfs_fw_dump_attr = {
  65. .attr = {
  66. .name = "fw_dump",
  67. .mode = S_IRUSR | S_IWUSR,
  68. },
  69. .size = 0,
  70. .read = qla2x00_sysfs_read_fw_dump,
  71. .write = qla2x00_sysfs_write_fw_dump,
  72. };
  73. static ssize_t
  74. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  75. struct bin_attribute *bin_attr,
  76. char *buf, loff_t off, size_t count)
  77. {
  78. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  79. struct device, kobj)));
  80. struct qla_hw_data *ha = vha->hw;
  81. if (!capable(CAP_SYS_ADMIN))
  82. return 0;
  83. /* Read NVRAM data from cache. */
  84. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  85. ha->nvram_size);
  86. }
  87. static ssize_t
  88. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  89. struct bin_attribute *bin_attr,
  90. char *buf, loff_t off, size_t count)
  91. {
  92. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  93. struct device, kobj)));
  94. struct qla_hw_data *ha = vha->hw;
  95. uint16_t cnt;
  96. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  97. return 0;
  98. /* Checksum NVRAM. */
  99. if (IS_FWI2_CAPABLE(ha)) {
  100. uint32_t *iter;
  101. uint32_t chksum;
  102. iter = (uint32_t *)buf;
  103. chksum = 0;
  104. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  105. chksum += le32_to_cpu(*iter++);
  106. chksum = ~chksum + 1;
  107. *iter = cpu_to_le32(chksum);
  108. } else {
  109. uint8_t *iter;
  110. uint8_t chksum;
  111. iter = (uint8_t *)buf;
  112. chksum = 0;
  113. for (cnt = 0; cnt < count - 1; cnt++)
  114. chksum += *iter++;
  115. chksum = ~chksum + 1;
  116. *iter = chksum;
  117. }
  118. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  119. qla_printk(KERN_WARNING, ha,
  120. "HBA not online, failing NVRAM update.\n");
  121. return -EAGAIN;
  122. }
  123. /* Write NVRAM. */
  124. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  125. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  126. count);
  127. /* NVRAM settings take effect immediately. */
  128. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  129. qla2xxx_wake_dpc(vha);
  130. qla2x00_wait_for_chip_reset(vha);
  131. return (count);
  132. }
  133. static struct bin_attribute sysfs_nvram_attr = {
  134. .attr = {
  135. .name = "nvram",
  136. .mode = S_IRUSR | S_IWUSR,
  137. },
  138. .size = 512,
  139. .read = qla2x00_sysfs_read_nvram,
  140. .write = qla2x00_sysfs_write_nvram,
  141. };
  142. static ssize_t
  143. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  144. struct bin_attribute *bin_attr,
  145. char *buf, loff_t off, size_t count)
  146. {
  147. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  148. struct device, kobj)));
  149. struct qla_hw_data *ha = vha->hw;
  150. if (ha->optrom_state != QLA_SREADING)
  151. return 0;
  152. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  153. ha->optrom_region_size);
  154. }
  155. static ssize_t
  156. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  157. struct bin_attribute *bin_attr,
  158. char *buf, loff_t off, size_t count)
  159. {
  160. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  161. struct device, kobj)));
  162. struct qla_hw_data *ha = vha->hw;
  163. if (ha->optrom_state != QLA_SWRITING)
  164. return -EINVAL;
  165. if (off > ha->optrom_region_size)
  166. return -ERANGE;
  167. if (off + count > ha->optrom_region_size)
  168. count = ha->optrom_region_size - off;
  169. memcpy(&ha->optrom_buffer[off], buf, count);
  170. return count;
  171. }
  172. static struct bin_attribute sysfs_optrom_attr = {
  173. .attr = {
  174. .name = "optrom",
  175. .mode = S_IRUSR | S_IWUSR,
  176. },
  177. .size = 0,
  178. .read = qla2x00_sysfs_read_optrom,
  179. .write = qla2x00_sysfs_write_optrom,
  180. };
  181. static ssize_t
  182. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  183. struct bin_attribute *bin_attr,
  184. char *buf, loff_t off, size_t count)
  185. {
  186. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  187. struct device, kobj)));
  188. struct qla_hw_data *ha = vha->hw;
  189. uint32_t start = 0;
  190. uint32_t size = ha->optrom_size;
  191. int val, valid;
  192. if (off)
  193. return 0;
  194. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  195. return -EINVAL;
  196. if (start > ha->optrom_size)
  197. return -EINVAL;
  198. switch (val) {
  199. case 0:
  200. if (ha->optrom_state != QLA_SREADING &&
  201. ha->optrom_state != QLA_SWRITING)
  202. break;
  203. ha->optrom_state = QLA_SWAITING;
  204. DEBUG2(qla_printk(KERN_INFO, ha,
  205. "Freeing flash region allocation -- 0x%x bytes.\n",
  206. ha->optrom_region_size));
  207. vfree(ha->optrom_buffer);
  208. ha->optrom_buffer = NULL;
  209. break;
  210. case 1:
  211. if (ha->optrom_state != QLA_SWAITING)
  212. break;
  213. ha->optrom_region_start = start;
  214. ha->optrom_region_size = start + size > ha->optrom_size ?
  215. ha->optrom_size - start : size;
  216. ha->optrom_state = QLA_SREADING;
  217. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  218. if (ha->optrom_buffer == NULL) {
  219. qla_printk(KERN_WARNING, ha,
  220. "Unable to allocate memory for optrom retrieval "
  221. "(%x).\n", ha->optrom_region_size);
  222. ha->optrom_state = QLA_SWAITING;
  223. return count;
  224. }
  225. DEBUG2(qla_printk(KERN_INFO, ha,
  226. "Reading flash region -- 0x%x/0x%x.\n",
  227. ha->optrom_region_start, ha->optrom_region_size));
  228. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  229. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  230. ha->optrom_region_start, ha->optrom_region_size);
  231. break;
  232. case 2:
  233. if (ha->optrom_state != QLA_SWAITING)
  234. break;
  235. /*
  236. * We need to be more restrictive on which FLASH regions are
  237. * allowed to be updated via user-space. Regions accessible
  238. * via this method include:
  239. *
  240. * ISP21xx/ISP22xx/ISP23xx type boards:
  241. *
  242. * 0x000000 -> 0x020000 -- Boot code.
  243. *
  244. * ISP2322/ISP24xx type boards:
  245. *
  246. * 0x000000 -> 0x07ffff -- Boot code.
  247. * 0x080000 -> 0x0fffff -- Firmware.
  248. *
  249. * ISP25xx type boards:
  250. *
  251. * 0x000000 -> 0x07ffff -- Boot code.
  252. * 0x080000 -> 0x0fffff -- Firmware.
  253. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  254. */
  255. valid = 0;
  256. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  257. valid = 1;
  258. else if (start == (ha->flt_region_boot * 4) ||
  259. start == (ha->flt_region_fw * 4))
  260. valid = 1;
  261. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  262. valid = 1;
  263. if (!valid) {
  264. qla_printk(KERN_WARNING, ha,
  265. "Invalid start region 0x%x/0x%x.\n", start, size);
  266. return -EINVAL;
  267. }
  268. ha->optrom_region_start = start;
  269. ha->optrom_region_size = start + size > ha->optrom_size ?
  270. ha->optrom_size - start : size;
  271. ha->optrom_state = QLA_SWRITING;
  272. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  273. if (ha->optrom_buffer == NULL) {
  274. qla_printk(KERN_WARNING, ha,
  275. "Unable to allocate memory for optrom update "
  276. "(%x).\n", ha->optrom_region_size);
  277. ha->optrom_state = QLA_SWAITING;
  278. return count;
  279. }
  280. DEBUG2(qla_printk(KERN_INFO, ha,
  281. "Staging flash region write -- 0x%x/0x%x.\n",
  282. ha->optrom_region_start, ha->optrom_region_size));
  283. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  284. break;
  285. case 3:
  286. if (ha->optrom_state != QLA_SWRITING)
  287. break;
  288. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  289. qla_printk(KERN_WARNING, ha,
  290. "HBA not online, failing flash update.\n");
  291. return -EAGAIN;
  292. }
  293. DEBUG2(qla_printk(KERN_INFO, ha,
  294. "Writing flash region -- 0x%x/0x%x.\n",
  295. ha->optrom_region_start, ha->optrom_region_size));
  296. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  297. ha->optrom_region_start, ha->optrom_region_size);
  298. break;
  299. default:
  300. count = -EINVAL;
  301. }
  302. return count;
  303. }
  304. static struct bin_attribute sysfs_optrom_ctl_attr = {
  305. .attr = {
  306. .name = "optrom_ctl",
  307. .mode = S_IWUSR,
  308. },
  309. .size = 0,
  310. .write = qla2x00_sysfs_write_optrom_ctl,
  311. };
  312. static ssize_t
  313. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  314. struct bin_attribute *bin_attr,
  315. char *buf, loff_t off, size_t count)
  316. {
  317. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  318. struct device, kobj)));
  319. struct qla_hw_data *ha = vha->hw;
  320. if (!capable(CAP_SYS_ADMIN))
  321. return 0;
  322. /* Read NVRAM data from cache. */
  323. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  324. }
  325. static ssize_t
  326. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  327. struct bin_attribute *bin_attr,
  328. char *buf, loff_t off, size_t count)
  329. {
  330. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  331. struct device, kobj)));
  332. struct qla_hw_data *ha = vha->hw;
  333. uint8_t *tmp_data;
  334. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  335. return 0;
  336. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  337. qla_printk(KERN_WARNING, ha,
  338. "HBA not online, failing VPD update.\n");
  339. return -EAGAIN;
  340. }
  341. /* Write NVRAM. */
  342. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  343. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  344. /* Update flash version information for 4Gb & above. */
  345. if (!IS_FWI2_CAPABLE(ha))
  346. goto done;
  347. tmp_data = vmalloc(256);
  348. if (!tmp_data) {
  349. qla_printk(KERN_WARNING, ha,
  350. "Unable to allocate memory for VPD information update.\n");
  351. goto done;
  352. }
  353. ha->isp_ops->get_flash_version(vha, tmp_data);
  354. vfree(tmp_data);
  355. done:
  356. return count;
  357. }
  358. static struct bin_attribute sysfs_vpd_attr = {
  359. .attr = {
  360. .name = "vpd",
  361. .mode = S_IRUSR | S_IWUSR,
  362. },
  363. .size = 0,
  364. .read = qla2x00_sysfs_read_vpd,
  365. .write = qla2x00_sysfs_write_vpd,
  366. };
  367. static ssize_t
  368. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  369. struct bin_attribute *bin_attr,
  370. char *buf, loff_t off, size_t count)
  371. {
  372. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  373. struct device, kobj)));
  374. struct qla_hw_data *ha = vha->hw;
  375. uint16_t iter, addr, offset;
  376. int rval;
  377. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  378. return 0;
  379. if (ha->sfp_data)
  380. goto do_read;
  381. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  382. &ha->sfp_data_dma);
  383. if (!ha->sfp_data) {
  384. qla_printk(KERN_WARNING, ha,
  385. "Unable to allocate memory for SFP read-data.\n");
  386. return 0;
  387. }
  388. do_read:
  389. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  390. addr = 0xa0;
  391. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  392. iter++, offset += SFP_BLOCK_SIZE) {
  393. if (iter == 4) {
  394. /* Skip to next device address. */
  395. addr = 0xa2;
  396. offset = 0;
  397. }
  398. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  399. SFP_BLOCK_SIZE);
  400. if (rval != QLA_SUCCESS) {
  401. qla_printk(KERN_WARNING, ha,
  402. "Unable to read SFP data (%x/%x/%x).\n", rval,
  403. addr, offset);
  404. count = 0;
  405. break;
  406. }
  407. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  408. buf += SFP_BLOCK_SIZE;
  409. }
  410. return count;
  411. }
  412. static struct bin_attribute sysfs_sfp_attr = {
  413. .attr = {
  414. .name = "sfp",
  415. .mode = S_IRUSR | S_IWUSR,
  416. },
  417. .size = SFP_DEV_SIZE * 2,
  418. .read = qla2x00_sysfs_read_sfp,
  419. };
  420. static ssize_t
  421. qla2x00_sysfs_write_reset(struct kobject *kobj,
  422. struct bin_attribute *bin_attr,
  423. char *buf, loff_t off, size_t count)
  424. {
  425. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  426. struct device, kobj)));
  427. struct qla_hw_data *ha = vha->hw;
  428. int type;
  429. if (off != 0)
  430. return 0;
  431. type = simple_strtol(buf, NULL, 10);
  432. switch (type) {
  433. case 0x2025c:
  434. qla_printk(KERN_INFO, ha,
  435. "Issuing ISP reset on (%ld).\n", vha->host_no);
  436. scsi_block_requests(vha->host);
  437. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  438. qla2xxx_wake_dpc(vha);
  439. qla2x00_wait_for_chip_reset(vha);
  440. scsi_unblock_requests(vha->host);
  441. break;
  442. case 0x2025d:
  443. if (!IS_QLA81XX(ha))
  444. break;
  445. qla_printk(KERN_INFO, ha,
  446. "Issuing MPI reset on (%ld).\n", vha->host_no);
  447. /* Make sure FC side is not in reset */
  448. qla2x00_wait_for_hba_online(vha);
  449. /* Issue MPI reset */
  450. scsi_block_requests(vha->host);
  451. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  452. qla_printk(KERN_WARNING, ha,
  453. "MPI reset failed on (%ld).\n", vha->host_no);
  454. scsi_unblock_requests(vha->host);
  455. break;
  456. }
  457. return count;
  458. }
  459. static struct bin_attribute sysfs_reset_attr = {
  460. .attr = {
  461. .name = "reset",
  462. .mode = S_IWUSR,
  463. },
  464. .size = 0,
  465. .write = qla2x00_sysfs_write_reset,
  466. };
  467. static struct sysfs_entry {
  468. char *name;
  469. struct bin_attribute *attr;
  470. int is4GBp_only;
  471. } bin_file_entries[] = {
  472. { "fw_dump", &sysfs_fw_dump_attr, },
  473. { "nvram", &sysfs_nvram_attr, },
  474. { "optrom", &sysfs_optrom_attr, },
  475. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  476. { "vpd", &sysfs_vpd_attr, 1 },
  477. { "sfp", &sysfs_sfp_attr, 1 },
  478. { "reset", &sysfs_reset_attr, },
  479. { NULL },
  480. };
  481. void
  482. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  483. {
  484. struct Scsi_Host *host = vha->host;
  485. struct sysfs_entry *iter;
  486. int ret;
  487. for (iter = bin_file_entries; iter->name; iter++) {
  488. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  489. continue;
  490. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  491. iter->attr);
  492. if (ret)
  493. qla_printk(KERN_INFO, vha->hw,
  494. "Unable to create sysfs %s binary attribute "
  495. "(%d).\n", iter->name, ret);
  496. }
  497. }
  498. void
  499. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  500. {
  501. struct Scsi_Host *host = vha->host;
  502. struct sysfs_entry *iter;
  503. struct qla_hw_data *ha = vha->hw;
  504. for (iter = bin_file_entries; iter->name; iter++) {
  505. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  506. continue;
  507. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  508. iter->attr);
  509. }
  510. if (ha->beacon_blink_led == 1)
  511. ha->isp_ops->beacon_off(vha);
  512. }
  513. /* Scsi_Host attributes. */
  514. static ssize_t
  515. qla2x00_drvr_version_show(struct device *dev,
  516. struct device_attribute *attr, char *buf)
  517. {
  518. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  519. }
  520. static ssize_t
  521. qla2x00_fw_version_show(struct device *dev,
  522. struct device_attribute *attr, char *buf)
  523. {
  524. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  525. struct qla_hw_data *ha = vha->hw;
  526. char fw_str[128];
  527. return snprintf(buf, PAGE_SIZE, "%s\n",
  528. ha->isp_ops->fw_version_str(vha, fw_str));
  529. }
  530. static ssize_t
  531. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  532. char *buf)
  533. {
  534. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  535. struct qla_hw_data *ha = vha->hw;
  536. uint32_t sn;
  537. if (IS_FWI2_CAPABLE(ha)) {
  538. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  539. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  540. }
  541. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  542. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  543. sn % 100000);
  544. }
  545. static ssize_t
  546. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  547. char *buf)
  548. {
  549. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  550. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  551. }
  552. static ssize_t
  553. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  554. char *buf)
  555. {
  556. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  557. struct qla_hw_data *ha = vha->hw;
  558. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  559. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  560. ha->product_id[3]);
  561. }
  562. static ssize_t
  563. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  564. char *buf)
  565. {
  566. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  567. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  568. }
  569. static ssize_t
  570. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  571. char *buf)
  572. {
  573. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  574. return snprintf(buf, PAGE_SIZE, "%s\n",
  575. vha->hw->model_desc ? vha->hw->model_desc : "");
  576. }
  577. static ssize_t
  578. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  579. char *buf)
  580. {
  581. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  582. char pci_info[30];
  583. return snprintf(buf, PAGE_SIZE, "%s\n",
  584. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  585. }
  586. static ssize_t
  587. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  588. char *buf)
  589. {
  590. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  591. struct qla_hw_data *ha = vha->hw;
  592. int len = 0;
  593. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  594. atomic_read(&vha->loop_state) == LOOP_DEAD)
  595. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  596. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  597. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  598. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  599. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  600. else {
  601. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  602. switch (ha->current_topology) {
  603. case ISP_CFG_NL:
  604. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  605. break;
  606. case ISP_CFG_FL:
  607. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  608. break;
  609. case ISP_CFG_N:
  610. len += snprintf(buf + len, PAGE_SIZE-len,
  611. "N_Port to N_Port\n");
  612. break;
  613. case ISP_CFG_F:
  614. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  615. break;
  616. default:
  617. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  618. break;
  619. }
  620. }
  621. return len;
  622. }
  623. static ssize_t
  624. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  625. char *buf)
  626. {
  627. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  628. int len = 0;
  629. switch (vha->hw->zio_mode) {
  630. case QLA_ZIO_MODE_6:
  631. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  632. break;
  633. case QLA_ZIO_DISABLED:
  634. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  635. break;
  636. }
  637. return len;
  638. }
  639. static ssize_t
  640. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  641. const char *buf, size_t count)
  642. {
  643. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  644. struct qla_hw_data *ha = vha->hw;
  645. int val = 0;
  646. uint16_t zio_mode;
  647. if (!IS_ZIO_SUPPORTED(ha))
  648. return -ENOTSUPP;
  649. if (sscanf(buf, "%d", &val) != 1)
  650. return -EINVAL;
  651. if (val)
  652. zio_mode = QLA_ZIO_MODE_6;
  653. else
  654. zio_mode = QLA_ZIO_DISABLED;
  655. /* Update per-hba values and queue a reset. */
  656. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  657. ha->zio_mode = zio_mode;
  658. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  659. }
  660. return strlen(buf);
  661. }
  662. static ssize_t
  663. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  664. char *buf)
  665. {
  666. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  667. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  668. }
  669. static ssize_t
  670. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  671. const char *buf, size_t count)
  672. {
  673. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  674. int val = 0;
  675. uint16_t zio_timer;
  676. if (sscanf(buf, "%d", &val) != 1)
  677. return -EINVAL;
  678. if (val > 25500 || val < 100)
  679. return -ERANGE;
  680. zio_timer = (uint16_t)(val / 100);
  681. vha->hw->zio_timer = zio_timer;
  682. return strlen(buf);
  683. }
  684. static ssize_t
  685. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  686. char *buf)
  687. {
  688. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  689. int len = 0;
  690. if (vha->hw->beacon_blink_led)
  691. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  692. else
  693. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  694. return len;
  695. }
  696. static ssize_t
  697. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  698. const char *buf, size_t count)
  699. {
  700. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  701. struct qla_hw_data *ha = vha->hw;
  702. int val = 0;
  703. int rval;
  704. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  705. return -EPERM;
  706. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  707. qla_printk(KERN_WARNING, ha,
  708. "Abort ISP active -- ignoring beacon request.\n");
  709. return -EBUSY;
  710. }
  711. if (sscanf(buf, "%d", &val) != 1)
  712. return -EINVAL;
  713. if (val)
  714. rval = ha->isp_ops->beacon_on(vha);
  715. else
  716. rval = ha->isp_ops->beacon_off(vha);
  717. if (rval != QLA_SUCCESS)
  718. count = 0;
  719. return count;
  720. }
  721. static ssize_t
  722. qla2x00_optrom_bios_version_show(struct device *dev,
  723. struct device_attribute *attr, char *buf)
  724. {
  725. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  726. struct qla_hw_data *ha = vha->hw;
  727. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  728. ha->bios_revision[0]);
  729. }
  730. static ssize_t
  731. qla2x00_optrom_efi_version_show(struct device *dev,
  732. struct device_attribute *attr, char *buf)
  733. {
  734. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  735. struct qla_hw_data *ha = vha->hw;
  736. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  737. ha->efi_revision[0]);
  738. }
  739. static ssize_t
  740. qla2x00_optrom_fcode_version_show(struct device *dev,
  741. struct device_attribute *attr, char *buf)
  742. {
  743. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  744. struct qla_hw_data *ha = vha->hw;
  745. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  746. ha->fcode_revision[0]);
  747. }
  748. static ssize_t
  749. qla2x00_optrom_fw_version_show(struct device *dev,
  750. struct device_attribute *attr, char *buf)
  751. {
  752. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  753. struct qla_hw_data *ha = vha->hw;
  754. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  755. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  756. ha->fw_revision[3]);
  757. }
  758. static ssize_t
  759. qla2x00_total_isp_aborts_show(struct device *dev,
  760. struct device_attribute *attr, char *buf)
  761. {
  762. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  763. struct qla_hw_data *ha = vha->hw;
  764. return snprintf(buf, PAGE_SIZE, "%d\n",
  765. ha->qla_stats.total_isp_aborts);
  766. }
  767. static ssize_t
  768. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  769. char *buf)
  770. {
  771. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  772. struct qla_hw_data *ha = vha->hw;
  773. if (!IS_QLA81XX(ha))
  774. return snprintf(buf, PAGE_SIZE, "\n");
  775. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  776. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  777. ha->mpi_capabilities);
  778. }
  779. static ssize_t
  780. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  781. char *buf)
  782. {
  783. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  784. struct qla_hw_data *ha = vha->hw;
  785. if (!IS_QLA81XX(ha))
  786. return snprintf(buf, PAGE_SIZE, "\n");
  787. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  788. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  789. }
  790. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  791. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  792. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  793. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  794. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  795. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  796. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  797. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  798. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  799. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  800. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  801. qla2x00_zio_timer_store);
  802. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  803. qla2x00_beacon_store);
  804. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  805. qla2x00_optrom_bios_version_show, NULL);
  806. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  807. qla2x00_optrom_efi_version_show, NULL);
  808. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  809. qla2x00_optrom_fcode_version_show, NULL);
  810. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  811. NULL);
  812. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  813. NULL);
  814. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  815. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  816. struct device_attribute *qla2x00_host_attrs[] = {
  817. &dev_attr_driver_version,
  818. &dev_attr_fw_version,
  819. &dev_attr_serial_num,
  820. &dev_attr_isp_name,
  821. &dev_attr_isp_id,
  822. &dev_attr_model_name,
  823. &dev_attr_model_desc,
  824. &dev_attr_pci_info,
  825. &dev_attr_link_state,
  826. &dev_attr_zio,
  827. &dev_attr_zio_timer,
  828. &dev_attr_beacon,
  829. &dev_attr_optrom_bios_version,
  830. &dev_attr_optrom_efi_version,
  831. &dev_attr_optrom_fcode_version,
  832. &dev_attr_optrom_fw_version,
  833. &dev_attr_total_isp_aborts,
  834. &dev_attr_mpi_version,
  835. &dev_attr_phy_version,
  836. NULL,
  837. };
  838. /* Host attributes. */
  839. static void
  840. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  841. {
  842. scsi_qla_host_t *vha = shost_priv(shost);
  843. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  844. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  845. }
  846. static void
  847. qla2x00_get_host_speed(struct Scsi_Host *shost)
  848. {
  849. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  850. (shost_priv(shost)))->hw;
  851. u32 speed = FC_PORTSPEED_UNKNOWN;
  852. switch (ha->link_data_rate) {
  853. case PORT_SPEED_1GB:
  854. speed = FC_PORTSPEED_1GBIT;
  855. break;
  856. case PORT_SPEED_2GB:
  857. speed = FC_PORTSPEED_2GBIT;
  858. break;
  859. case PORT_SPEED_4GB:
  860. speed = FC_PORTSPEED_4GBIT;
  861. break;
  862. case PORT_SPEED_8GB:
  863. speed = FC_PORTSPEED_8GBIT;
  864. break;
  865. case PORT_SPEED_10GB:
  866. speed = FC_PORTSPEED_10GBIT;
  867. break;
  868. }
  869. fc_host_speed(shost) = speed;
  870. }
  871. static void
  872. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  873. {
  874. scsi_qla_host_t *vha = shost_priv(shost);
  875. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  876. if (vha->vp_idx) {
  877. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  878. return;
  879. }
  880. switch (vha->hw->current_topology) {
  881. case ISP_CFG_NL:
  882. port_type = FC_PORTTYPE_LPORT;
  883. break;
  884. case ISP_CFG_FL:
  885. port_type = FC_PORTTYPE_NLPORT;
  886. break;
  887. case ISP_CFG_N:
  888. port_type = FC_PORTTYPE_PTP;
  889. break;
  890. case ISP_CFG_F:
  891. port_type = FC_PORTTYPE_NPORT;
  892. break;
  893. }
  894. fc_host_port_type(shost) = port_type;
  895. }
  896. static void
  897. qla2x00_get_starget_node_name(struct scsi_target *starget)
  898. {
  899. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  900. scsi_qla_host_t *vha = shost_priv(host);
  901. fc_port_t *fcport;
  902. u64 node_name = 0;
  903. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  904. if (fcport->rport &&
  905. starget->id == fcport->rport->scsi_target_id) {
  906. node_name = wwn_to_u64(fcport->node_name);
  907. break;
  908. }
  909. }
  910. fc_starget_node_name(starget) = node_name;
  911. }
  912. static void
  913. qla2x00_get_starget_port_name(struct scsi_target *starget)
  914. {
  915. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  916. scsi_qla_host_t *vha = shost_priv(host);
  917. fc_port_t *fcport;
  918. u64 port_name = 0;
  919. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  920. if (fcport->rport &&
  921. starget->id == fcport->rport->scsi_target_id) {
  922. port_name = wwn_to_u64(fcport->port_name);
  923. break;
  924. }
  925. }
  926. fc_starget_port_name(starget) = port_name;
  927. }
  928. static void
  929. qla2x00_get_starget_port_id(struct scsi_target *starget)
  930. {
  931. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  932. scsi_qla_host_t *vha = shost_priv(host);
  933. fc_port_t *fcport;
  934. uint32_t port_id = ~0U;
  935. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  936. if (fcport->rport &&
  937. starget->id == fcport->rport->scsi_target_id) {
  938. port_id = fcport->d_id.b.domain << 16 |
  939. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  940. break;
  941. }
  942. }
  943. fc_starget_port_id(starget) = port_id;
  944. }
  945. static void
  946. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  947. {
  948. if (timeout)
  949. rport->dev_loss_tmo = timeout;
  950. else
  951. rport->dev_loss_tmo = 1;
  952. }
  953. static void
  954. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  955. {
  956. struct Scsi_Host *host = rport_to_shost(rport);
  957. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  958. if (!fcport)
  959. return;
  960. qla2x00_abort_fcport_cmds(fcport);
  961. /*
  962. * Transport has effectively 'deleted' the rport, clear
  963. * all local references.
  964. */
  965. spin_lock_irq(host->host_lock);
  966. fcport->rport = NULL;
  967. *((fc_port_t **)rport->dd_data) = NULL;
  968. spin_unlock_irq(host->host_lock);
  969. }
  970. static void
  971. qla2x00_terminate_rport_io(struct fc_rport *rport)
  972. {
  973. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  974. if (!fcport)
  975. return;
  976. /*
  977. * At this point all fcport's software-states are cleared. Perform any
  978. * final cleanup of firmware resources (PCBs and XCBs).
  979. */
  980. if (fcport->loop_id != FC_NO_LOOP_ID)
  981. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  982. fcport->loop_id, fcport->d_id.b.domain,
  983. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  984. qla2x00_abort_fcport_cmds(fcport);
  985. }
  986. static int
  987. qla2x00_issue_lip(struct Scsi_Host *shost)
  988. {
  989. scsi_qla_host_t *vha = shost_priv(shost);
  990. qla2x00_loop_reset(vha);
  991. return 0;
  992. }
  993. static struct fc_host_statistics *
  994. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  995. {
  996. scsi_qla_host_t *vha = shost_priv(shost);
  997. struct qla_hw_data *ha = vha->hw;
  998. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  999. int rval;
  1000. struct link_statistics *stats;
  1001. dma_addr_t stats_dma;
  1002. struct fc_host_statistics *pfc_host_stat;
  1003. pfc_host_stat = &ha->fc_host_stat;
  1004. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1005. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1006. if (stats == NULL) {
  1007. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1008. __func__, base_vha->host_no));
  1009. goto done;
  1010. }
  1011. memset(stats, 0, DMA_POOL_SIZE);
  1012. rval = QLA_FUNCTION_FAILED;
  1013. if (IS_FWI2_CAPABLE(ha)) {
  1014. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1015. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1016. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1017. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1018. !ha->dpc_active) {
  1019. /* Must be in a 'READY' state for statistics retrieval. */
  1020. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1021. stats, stats_dma);
  1022. }
  1023. if (rval != QLA_SUCCESS)
  1024. goto done_free;
  1025. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1026. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1027. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1028. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1029. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1030. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1031. if (IS_FWI2_CAPABLE(ha)) {
  1032. pfc_host_stat->lip_count = stats->lip_cnt;
  1033. pfc_host_stat->tx_frames = stats->tx_frames;
  1034. pfc_host_stat->rx_frames = stats->rx_frames;
  1035. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1036. pfc_host_stat->nos_count = stats->nos_rcvd;
  1037. }
  1038. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1039. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1040. done_free:
  1041. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1042. done:
  1043. return pfc_host_stat;
  1044. }
  1045. static void
  1046. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1047. {
  1048. scsi_qla_host_t *vha = shost_priv(shost);
  1049. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1050. }
  1051. static void
  1052. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(shost);
  1055. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1056. }
  1057. static void
  1058. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1059. {
  1060. scsi_qla_host_t *vha = shost_priv(shost);
  1061. u64 node_name;
  1062. if (vha->device_flags & SWITCH_FOUND)
  1063. node_name = wwn_to_u64(vha->fabric_node_name);
  1064. else
  1065. node_name = wwn_to_u64(vha->node_name);
  1066. fc_host_fabric_name(shost) = node_name;
  1067. }
  1068. static void
  1069. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1070. {
  1071. scsi_qla_host_t *vha = shost_priv(shost);
  1072. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1073. if (!base_vha->flags.online)
  1074. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1075. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1076. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1077. else
  1078. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1079. }
  1080. static int
  1081. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1082. {
  1083. int ret = 0;
  1084. int cnt = 0;
  1085. uint8_t qos = QLA_DEFAULT_QUE_QOS;
  1086. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1087. scsi_qla_host_t *vha = NULL;
  1088. struct qla_hw_data *ha = base_vha->hw;
  1089. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1090. if (ret) {
  1091. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1092. "status %x\n", ret));
  1093. return (ret);
  1094. }
  1095. vha = qla24xx_create_vhost(fc_vport);
  1096. if (vha == NULL) {
  1097. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1098. vha));
  1099. return FC_VPORT_FAILED;
  1100. }
  1101. if (disable) {
  1102. atomic_set(&vha->vp_state, VP_OFFLINE);
  1103. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1104. } else
  1105. atomic_set(&vha->vp_state, VP_FAILED);
  1106. /* ready to create vport */
  1107. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1108. vha->vp_idx);
  1109. /* initialized vport states */
  1110. atomic_set(&vha->loop_state, LOOP_DOWN);
  1111. vha->vp_err_state= VP_ERR_PORTDWN;
  1112. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1113. /* Check if physical ha port is Up */
  1114. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1115. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1116. /* Don't retry or attempt login of this virtual port */
  1117. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1118. base_vha->host_no));
  1119. atomic_set(&vha->loop_state, LOOP_DEAD);
  1120. if (!disable)
  1121. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1122. }
  1123. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  1124. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1125. vha->host_no, vha->vp_idx));
  1126. goto vport_create_failed_2;
  1127. }
  1128. /* initialize attributes */
  1129. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1130. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1131. fc_host_supported_classes(vha->host) =
  1132. fc_host_supported_classes(base_vha->host);
  1133. fc_host_supported_speeds(vha->host) =
  1134. fc_host_supported_speeds(base_vha->host);
  1135. qla24xx_vport_disable(fc_vport, disable);
  1136. /* Create a queue pair for the vport */
  1137. if (ha->mqenable) {
  1138. if (ha->npiv_info) {
  1139. for (; cnt < ha->nvram_npiv_size; cnt++) {
  1140. if (ha->npiv_info[cnt].port_name ==
  1141. vha->port_name &&
  1142. ha->npiv_info[cnt].node_name ==
  1143. vha->node_name) {
  1144. qos = ha->npiv_info[cnt].q_qos;
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. qla25xx_create_queues(vha, qos);
  1150. }
  1151. return 0;
  1152. vport_create_failed_2:
  1153. qla24xx_disable_vp(vha);
  1154. qla24xx_deallocate_vp_id(vha);
  1155. scsi_host_put(vha->host);
  1156. return FC_VPORT_FAILED;
  1157. }
  1158. static int
  1159. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1160. {
  1161. scsi_qla_host_t *vha = fc_vport->dd_data;
  1162. fc_port_t *fcport, *tfcport;
  1163. struct qla_hw_data *ha = vha->hw;
  1164. uint16_t id = vha->vp_idx;
  1165. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1166. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1167. msleep(1000);
  1168. qla24xx_disable_vp(vha);
  1169. fc_remove_host(vha->host);
  1170. scsi_remove_host(vha->host);
  1171. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1172. list_del(&fcport->list);
  1173. kfree(fcport);
  1174. fcport = NULL;
  1175. }
  1176. qla24xx_deallocate_vp_id(vha);
  1177. if (vha->timer_active) {
  1178. qla2x00_vp_stop_timer(vha);
  1179. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1180. "has stopped\n",
  1181. vha->host_no, vha->vp_idx, vha));
  1182. }
  1183. if (ha->mqenable) {
  1184. if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
  1185. qla_printk(KERN_WARNING, ha,
  1186. "Queue delete failed.\n");
  1187. }
  1188. scsi_host_put(vha->host);
  1189. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1190. return 0;
  1191. }
  1192. static int
  1193. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1194. {
  1195. scsi_qla_host_t *vha = fc_vport->dd_data;
  1196. if (disable)
  1197. qla24xx_disable_vp(vha);
  1198. else
  1199. qla24xx_enable_vp(vha);
  1200. return 0;
  1201. }
  1202. struct fc_function_template qla2xxx_transport_functions = {
  1203. .show_host_node_name = 1,
  1204. .show_host_port_name = 1,
  1205. .show_host_supported_classes = 1,
  1206. .show_host_supported_speeds = 1,
  1207. .get_host_port_id = qla2x00_get_host_port_id,
  1208. .show_host_port_id = 1,
  1209. .get_host_speed = qla2x00_get_host_speed,
  1210. .show_host_speed = 1,
  1211. .get_host_port_type = qla2x00_get_host_port_type,
  1212. .show_host_port_type = 1,
  1213. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1214. .show_host_symbolic_name = 1,
  1215. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1216. .show_host_system_hostname = 1,
  1217. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1218. .show_host_fabric_name = 1,
  1219. .get_host_port_state = qla2x00_get_host_port_state,
  1220. .show_host_port_state = 1,
  1221. .dd_fcrport_size = sizeof(struct fc_port *),
  1222. .show_rport_supported_classes = 1,
  1223. .get_starget_node_name = qla2x00_get_starget_node_name,
  1224. .show_starget_node_name = 1,
  1225. .get_starget_port_name = qla2x00_get_starget_port_name,
  1226. .show_starget_port_name = 1,
  1227. .get_starget_port_id = qla2x00_get_starget_port_id,
  1228. .show_starget_port_id = 1,
  1229. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1230. .show_rport_dev_loss_tmo = 1,
  1231. .issue_fc_host_lip = qla2x00_issue_lip,
  1232. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1233. .terminate_rport_io = qla2x00_terminate_rport_io,
  1234. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1235. .vport_create = qla24xx_vport_create,
  1236. .vport_disable = qla24xx_vport_disable,
  1237. .vport_delete = qla24xx_vport_delete,
  1238. };
  1239. struct fc_function_template qla2xxx_transport_vport_functions = {
  1240. .show_host_node_name = 1,
  1241. .show_host_port_name = 1,
  1242. .show_host_supported_classes = 1,
  1243. .get_host_port_id = qla2x00_get_host_port_id,
  1244. .show_host_port_id = 1,
  1245. .get_host_speed = qla2x00_get_host_speed,
  1246. .show_host_speed = 1,
  1247. .get_host_port_type = qla2x00_get_host_port_type,
  1248. .show_host_port_type = 1,
  1249. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1250. .show_host_symbolic_name = 1,
  1251. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1252. .show_host_system_hostname = 1,
  1253. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1254. .show_host_fabric_name = 1,
  1255. .get_host_port_state = qla2x00_get_host_port_state,
  1256. .show_host_port_state = 1,
  1257. .dd_fcrport_size = sizeof(struct fc_port *),
  1258. .show_rport_supported_classes = 1,
  1259. .get_starget_node_name = qla2x00_get_starget_node_name,
  1260. .show_starget_node_name = 1,
  1261. .get_starget_port_name = qla2x00_get_starget_port_name,
  1262. .show_starget_port_name = 1,
  1263. .get_starget_port_id = qla2x00_get_starget_port_id,
  1264. .show_starget_port_id = 1,
  1265. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1266. .show_rport_dev_loss_tmo = 1,
  1267. .issue_fc_host_lip = qla2x00_issue_lip,
  1268. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1269. .terminate_rport_io = qla2x00_terminate_rport_io,
  1270. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1271. };
  1272. void
  1273. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1274. {
  1275. struct qla_hw_data *ha = vha->hw;
  1276. u32 speed = FC_PORTSPEED_UNKNOWN;
  1277. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1278. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1279. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1280. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1281. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1282. if (IS_QLA81XX(ha))
  1283. speed = FC_PORTSPEED_10GBIT;
  1284. else if (IS_QLA25XX(ha))
  1285. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1286. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1287. else if (IS_QLA24XX_TYPE(ha))
  1288. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1289. FC_PORTSPEED_1GBIT;
  1290. else if (IS_QLA23XX(ha))
  1291. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1292. else
  1293. speed = FC_PORTSPEED_1GBIT;
  1294. fc_host_supported_speeds(vha->host) = speed;
  1295. }