qla_attr.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. /* SYSFS attributes --------------------------------------------------------- */
  14. static ssize_t
  15. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  16. struct bin_attribute *bin_attr,
  17. char *buf, loff_t off, size_t count)
  18. {
  19. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  20. struct device, kobj)));
  21. struct qla_hw_data *ha = vha->hw;
  22. if (ha->fw_dump_reading == 0)
  23. return 0;
  24. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  25. ha->fw_dump_len);
  26. }
  27. static ssize_t
  28. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  29. struct bin_attribute *bin_attr,
  30. char *buf, loff_t off, size_t count)
  31. {
  32. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  33. struct device, kobj)));
  34. struct qla_hw_data *ha = vha->hw;
  35. int reading;
  36. if (IS_QLA82XX(ha)) {
  37. DEBUG2(qla_printk(KERN_INFO, ha,
  38. "Firmware dump not supported for ISP82xx\n"));
  39. return count;
  40. }
  41. if (off != 0)
  42. return (0);
  43. reading = simple_strtol(buf, NULL, 10);
  44. switch (reading) {
  45. case 0:
  46. if (!ha->fw_dump_reading)
  47. break;
  48. qla_printk(KERN_INFO, ha,
  49. "Firmware dump cleared on (%ld).\n", vha->host_no);
  50. ha->fw_dump_reading = 0;
  51. ha->fw_dumped = 0;
  52. break;
  53. case 1:
  54. if (ha->fw_dumped && !ha->fw_dump_reading) {
  55. ha->fw_dump_reading = 1;
  56. qla_printk(KERN_INFO, ha,
  57. "Raw firmware dump ready for read on (%ld).\n",
  58. vha->host_no);
  59. }
  60. break;
  61. case 2:
  62. qla2x00_alloc_fw_dump(vha);
  63. break;
  64. case 3:
  65. qla2x00_system_error(vha);
  66. break;
  67. }
  68. return (count);
  69. }
  70. static struct bin_attribute sysfs_fw_dump_attr = {
  71. .attr = {
  72. .name = "fw_dump",
  73. .mode = S_IRUSR | S_IWUSR,
  74. },
  75. .size = 0,
  76. .read = qla2x00_sysfs_read_fw_dump,
  77. .write = qla2x00_sysfs_write_fw_dump,
  78. };
  79. static ssize_t
  80. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  81. struct bin_attribute *bin_attr,
  82. char *buf, loff_t off, size_t count)
  83. {
  84. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  85. struct device, kobj)));
  86. struct qla_hw_data *ha = vha->hw;
  87. if (!capable(CAP_SYS_ADMIN))
  88. return 0;
  89. if (IS_NOCACHE_VPD_TYPE(ha))
  90. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  91. ha->nvram_size);
  92. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  93. ha->nvram_size);
  94. }
  95. static ssize_t
  96. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  97. struct bin_attribute *bin_attr,
  98. char *buf, loff_t off, size_t count)
  99. {
  100. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  101. struct device, kobj)));
  102. struct qla_hw_data *ha = vha->hw;
  103. uint16_t cnt;
  104. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  105. !ha->isp_ops->write_nvram)
  106. return 0;
  107. /* Checksum NVRAM. */
  108. if (IS_FWI2_CAPABLE(ha)) {
  109. uint32_t *iter;
  110. uint32_t chksum;
  111. iter = (uint32_t *)buf;
  112. chksum = 0;
  113. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  114. chksum += le32_to_cpu(*iter++);
  115. chksum = ~chksum + 1;
  116. *iter = cpu_to_le32(chksum);
  117. } else {
  118. uint8_t *iter;
  119. uint8_t chksum;
  120. iter = (uint8_t *)buf;
  121. chksum = 0;
  122. for (cnt = 0; cnt < count - 1; cnt++)
  123. chksum += *iter++;
  124. chksum = ~chksum + 1;
  125. *iter = chksum;
  126. }
  127. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  128. qla_printk(KERN_WARNING, ha,
  129. "HBA not online, failing NVRAM update.\n");
  130. return -EAGAIN;
  131. }
  132. /* Write NVRAM. */
  133. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  134. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  135. count);
  136. /* NVRAM settings take effect immediately. */
  137. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  138. qla2xxx_wake_dpc(vha);
  139. qla2x00_wait_for_chip_reset(vha);
  140. return (count);
  141. }
  142. static struct bin_attribute sysfs_nvram_attr = {
  143. .attr = {
  144. .name = "nvram",
  145. .mode = S_IRUSR | S_IWUSR,
  146. },
  147. .size = 512,
  148. .read = qla2x00_sysfs_read_nvram,
  149. .write = qla2x00_sysfs_write_nvram,
  150. };
  151. static ssize_t
  152. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  153. struct bin_attribute *bin_attr,
  154. char *buf, loff_t off, size_t count)
  155. {
  156. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  157. struct device, kobj)));
  158. struct qla_hw_data *ha = vha->hw;
  159. if (ha->optrom_state != QLA_SREADING)
  160. return 0;
  161. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  162. ha->optrom_region_size);
  163. }
  164. static ssize_t
  165. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  166. struct bin_attribute *bin_attr,
  167. char *buf, loff_t off, size_t count)
  168. {
  169. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  170. struct device, kobj)));
  171. struct qla_hw_data *ha = vha->hw;
  172. if (ha->optrom_state != QLA_SWRITING)
  173. return -EINVAL;
  174. if (off > ha->optrom_region_size)
  175. return -ERANGE;
  176. if (off + count > ha->optrom_region_size)
  177. count = ha->optrom_region_size - off;
  178. memcpy(&ha->optrom_buffer[off], buf, count);
  179. return count;
  180. }
  181. static struct bin_attribute sysfs_optrom_attr = {
  182. .attr = {
  183. .name = "optrom",
  184. .mode = S_IRUSR | S_IWUSR,
  185. },
  186. .size = 0,
  187. .read = qla2x00_sysfs_read_optrom,
  188. .write = qla2x00_sysfs_write_optrom,
  189. };
  190. static ssize_t
  191. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  192. struct bin_attribute *bin_attr,
  193. char *buf, loff_t off, size_t count)
  194. {
  195. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  196. struct device, kobj)));
  197. struct qla_hw_data *ha = vha->hw;
  198. uint32_t start = 0;
  199. uint32_t size = ha->optrom_size;
  200. int val, valid;
  201. if (off)
  202. return 0;
  203. if (unlikely(pci_channel_offline(ha->pdev)))
  204. return 0;
  205. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  206. return -EINVAL;
  207. if (start > ha->optrom_size)
  208. return -EINVAL;
  209. switch (val) {
  210. case 0:
  211. if (ha->optrom_state != QLA_SREADING &&
  212. ha->optrom_state != QLA_SWRITING)
  213. break;
  214. ha->optrom_state = QLA_SWAITING;
  215. DEBUG2(qla_printk(KERN_INFO, ha,
  216. "Freeing flash region allocation -- 0x%x bytes.\n",
  217. ha->optrom_region_size));
  218. vfree(ha->optrom_buffer);
  219. ha->optrom_buffer = NULL;
  220. break;
  221. case 1:
  222. if (ha->optrom_state != QLA_SWAITING)
  223. break;
  224. ha->optrom_region_start = start;
  225. ha->optrom_region_size = start + size > ha->optrom_size ?
  226. ha->optrom_size - start : size;
  227. ha->optrom_state = QLA_SREADING;
  228. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  229. if (ha->optrom_buffer == NULL) {
  230. qla_printk(KERN_WARNING, ha,
  231. "Unable to allocate memory for optrom retrieval "
  232. "(%x).\n", ha->optrom_region_size);
  233. ha->optrom_state = QLA_SWAITING;
  234. return count;
  235. }
  236. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  237. qla_printk(KERN_WARNING, ha,
  238. "HBA not online, failing NVRAM update.\n");
  239. return -EAGAIN;
  240. }
  241. DEBUG2(qla_printk(KERN_INFO, ha,
  242. "Reading flash region -- 0x%x/0x%x.\n",
  243. ha->optrom_region_start, ha->optrom_region_size));
  244. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  245. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  246. ha->optrom_region_start, ha->optrom_region_size);
  247. break;
  248. case 2:
  249. if (ha->optrom_state != QLA_SWAITING)
  250. break;
  251. /*
  252. * We need to be more restrictive on which FLASH regions are
  253. * allowed to be updated via user-space. Regions accessible
  254. * via this method include:
  255. *
  256. * ISP21xx/ISP22xx/ISP23xx type boards:
  257. *
  258. * 0x000000 -> 0x020000 -- Boot code.
  259. *
  260. * ISP2322/ISP24xx type boards:
  261. *
  262. * 0x000000 -> 0x07ffff -- Boot code.
  263. * 0x080000 -> 0x0fffff -- Firmware.
  264. *
  265. * ISP25xx type boards:
  266. *
  267. * 0x000000 -> 0x07ffff -- Boot code.
  268. * 0x080000 -> 0x0fffff -- Firmware.
  269. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  270. */
  271. valid = 0;
  272. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  273. valid = 1;
  274. else if (start == (ha->flt_region_boot * 4) ||
  275. start == (ha->flt_region_fw * 4))
  276. valid = 1;
  277. else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
  278. valid = 1;
  279. if (!valid) {
  280. qla_printk(KERN_WARNING, ha,
  281. "Invalid start region 0x%x/0x%x.\n", start, size);
  282. return -EINVAL;
  283. }
  284. ha->optrom_region_start = start;
  285. ha->optrom_region_size = start + size > ha->optrom_size ?
  286. ha->optrom_size - start : size;
  287. ha->optrom_state = QLA_SWRITING;
  288. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  289. if (ha->optrom_buffer == NULL) {
  290. qla_printk(KERN_WARNING, ha,
  291. "Unable to allocate memory for optrom update "
  292. "(%x).\n", ha->optrom_region_size);
  293. ha->optrom_state = QLA_SWAITING;
  294. return count;
  295. }
  296. DEBUG2(qla_printk(KERN_INFO, ha,
  297. "Staging flash region write -- 0x%x/0x%x.\n",
  298. ha->optrom_region_start, ha->optrom_region_size));
  299. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  300. break;
  301. case 3:
  302. if (ha->optrom_state != QLA_SWRITING)
  303. break;
  304. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  305. qla_printk(KERN_WARNING, ha,
  306. "HBA not online, failing flash update.\n");
  307. return -EAGAIN;
  308. }
  309. DEBUG2(qla_printk(KERN_INFO, ha,
  310. "Writing flash region -- 0x%x/0x%x.\n",
  311. ha->optrom_region_start, ha->optrom_region_size));
  312. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  313. ha->optrom_region_start, ha->optrom_region_size);
  314. break;
  315. default:
  316. count = -EINVAL;
  317. }
  318. return count;
  319. }
  320. static struct bin_attribute sysfs_optrom_ctl_attr = {
  321. .attr = {
  322. .name = "optrom_ctl",
  323. .mode = S_IWUSR,
  324. },
  325. .size = 0,
  326. .write = qla2x00_sysfs_write_optrom_ctl,
  327. };
  328. static ssize_t
  329. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  330. struct bin_attribute *bin_attr,
  331. char *buf, loff_t off, size_t count)
  332. {
  333. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  334. struct device, kobj)));
  335. struct qla_hw_data *ha = vha->hw;
  336. if (unlikely(pci_channel_offline(ha->pdev)))
  337. return 0;
  338. if (!capable(CAP_SYS_ADMIN))
  339. return 0;
  340. if (IS_NOCACHE_VPD_TYPE(ha))
  341. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  342. ha->vpd_size);
  343. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  344. }
  345. static ssize_t
  346. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  347. struct bin_attribute *bin_attr,
  348. char *buf, loff_t off, size_t count)
  349. {
  350. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  351. struct device, kobj)));
  352. struct qla_hw_data *ha = vha->hw;
  353. uint8_t *tmp_data;
  354. if (unlikely(pci_channel_offline(ha->pdev)))
  355. return 0;
  356. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  357. !ha->isp_ops->write_nvram)
  358. return 0;
  359. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  360. qla_printk(KERN_WARNING, ha,
  361. "HBA not online, failing VPD update.\n");
  362. return -EAGAIN;
  363. }
  364. /* Write NVRAM. */
  365. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  366. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  367. /* Update flash version information for 4Gb & above. */
  368. if (!IS_FWI2_CAPABLE(ha))
  369. goto done;
  370. tmp_data = vmalloc(256);
  371. if (!tmp_data) {
  372. qla_printk(KERN_WARNING, ha,
  373. "Unable to allocate memory for VPD information update.\n");
  374. goto done;
  375. }
  376. ha->isp_ops->get_flash_version(vha, tmp_data);
  377. vfree(tmp_data);
  378. done:
  379. return count;
  380. }
  381. static struct bin_attribute sysfs_vpd_attr = {
  382. .attr = {
  383. .name = "vpd",
  384. .mode = S_IRUSR | S_IWUSR,
  385. },
  386. .size = 0,
  387. .read = qla2x00_sysfs_read_vpd,
  388. .write = qla2x00_sysfs_write_vpd,
  389. };
  390. static ssize_t
  391. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  392. struct bin_attribute *bin_attr,
  393. char *buf, loff_t off, size_t count)
  394. {
  395. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  396. struct device, kobj)));
  397. struct qla_hw_data *ha = vha->hw;
  398. uint16_t iter, addr, offset;
  399. int rval;
  400. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  401. return 0;
  402. if (ha->sfp_data)
  403. goto do_read;
  404. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  405. &ha->sfp_data_dma);
  406. if (!ha->sfp_data) {
  407. qla_printk(KERN_WARNING, ha,
  408. "Unable to allocate memory for SFP read-data.\n");
  409. return 0;
  410. }
  411. do_read:
  412. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  413. addr = 0xa0;
  414. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  415. iter++, offset += SFP_BLOCK_SIZE) {
  416. if (iter == 4) {
  417. /* Skip to next device address. */
  418. addr = 0xa2;
  419. offset = 0;
  420. }
  421. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  422. SFP_BLOCK_SIZE);
  423. if (rval != QLA_SUCCESS) {
  424. qla_printk(KERN_WARNING, ha,
  425. "Unable to read SFP data (%x/%x/%x).\n", rval,
  426. addr, offset);
  427. count = 0;
  428. break;
  429. }
  430. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  431. buf += SFP_BLOCK_SIZE;
  432. }
  433. return count;
  434. }
  435. static struct bin_attribute sysfs_sfp_attr = {
  436. .attr = {
  437. .name = "sfp",
  438. .mode = S_IRUSR | S_IWUSR,
  439. },
  440. .size = SFP_DEV_SIZE * 2,
  441. .read = qla2x00_sysfs_read_sfp,
  442. };
  443. static ssize_t
  444. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  445. struct bin_attribute *bin_attr,
  446. char *buf, loff_t off, size_t count)
  447. {
  448. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  449. struct device, kobj)));
  450. struct qla_hw_data *ha = vha->hw;
  451. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  452. int type;
  453. if (off != 0)
  454. return 0;
  455. type = simple_strtol(buf, NULL, 10);
  456. switch (type) {
  457. case 0x2025c:
  458. qla_printk(KERN_INFO, ha,
  459. "Issuing ISP reset on (%ld).\n", vha->host_no);
  460. scsi_block_requests(vha->host);
  461. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  462. qla2xxx_wake_dpc(vha);
  463. qla2x00_wait_for_chip_reset(vha);
  464. scsi_unblock_requests(vha->host);
  465. break;
  466. case 0x2025d:
  467. if (!IS_QLA81XX(ha))
  468. break;
  469. qla_printk(KERN_INFO, ha,
  470. "Issuing MPI reset on (%ld).\n", vha->host_no);
  471. /* Make sure FC side is not in reset */
  472. qla2x00_wait_for_hba_online(vha);
  473. /* Issue MPI reset */
  474. scsi_block_requests(vha->host);
  475. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  476. qla_printk(KERN_WARNING, ha,
  477. "MPI reset failed on (%ld).\n", vha->host_no);
  478. scsi_unblock_requests(vha->host);
  479. break;
  480. case 0x2025e:
  481. if (!IS_QLA82XX(ha) || vha != base_vha) {
  482. qla_printk(KERN_INFO, ha,
  483. "FCoE ctx reset not supported for host%ld.\n",
  484. vha->host_no);
  485. return count;
  486. }
  487. qla_printk(KERN_INFO, ha,
  488. "Issuing FCoE CTX reset on host%ld.\n", vha->host_no);
  489. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  490. qla2xxx_wake_dpc(vha);
  491. qla2x00_wait_for_fcoe_ctx_reset(vha);
  492. break;
  493. }
  494. return count;
  495. }
  496. static struct bin_attribute sysfs_reset_attr = {
  497. .attr = {
  498. .name = "reset",
  499. .mode = S_IWUSR,
  500. },
  501. .size = 0,
  502. .write = qla2x00_sysfs_write_reset,
  503. };
  504. static ssize_t
  505. qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
  506. struct bin_attribute *bin_attr,
  507. char *buf, loff_t off, size_t count)
  508. {
  509. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  510. struct device, kobj)));
  511. struct qla_hw_data *ha = vha->hw;
  512. uint16_t dev, adr, opt, len;
  513. int rval;
  514. ha->edc_data_len = 0;
  515. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  516. return 0;
  517. if (!ha->edc_data) {
  518. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  519. &ha->edc_data_dma);
  520. if (!ha->edc_data) {
  521. DEBUG2(qla_printk(KERN_INFO, ha,
  522. "Unable to allocate memory for EDC write.\n"));
  523. return 0;
  524. }
  525. }
  526. dev = le16_to_cpup((void *)&buf[0]);
  527. adr = le16_to_cpup((void *)&buf[2]);
  528. opt = le16_to_cpup((void *)&buf[4]);
  529. len = le16_to_cpup((void *)&buf[6]);
  530. if (!(opt & BIT_0))
  531. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  532. return -EINVAL;
  533. memcpy(ha->edc_data, &buf[8], len);
  534. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  535. ha->edc_data, len, opt);
  536. if (rval != QLA_SUCCESS) {
  537. DEBUG2(qla_printk(KERN_INFO, ha,
  538. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  539. rval, dev, adr, opt, len, *buf));
  540. return 0;
  541. }
  542. return count;
  543. }
  544. static struct bin_attribute sysfs_edc_attr = {
  545. .attr = {
  546. .name = "edc",
  547. .mode = S_IWUSR,
  548. },
  549. .size = 0,
  550. .write = qla2x00_sysfs_write_edc,
  551. };
  552. static ssize_t
  553. qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
  554. struct bin_attribute *bin_attr,
  555. char *buf, loff_t off, size_t count)
  556. {
  557. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  558. struct device, kobj)));
  559. struct qla_hw_data *ha = vha->hw;
  560. uint16_t dev, adr, opt, len;
  561. int rval;
  562. ha->edc_data_len = 0;
  563. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  564. return 0;
  565. if (!ha->edc_data) {
  566. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  567. &ha->edc_data_dma);
  568. if (!ha->edc_data) {
  569. DEBUG2(qla_printk(KERN_INFO, ha,
  570. "Unable to allocate memory for EDC status.\n"));
  571. return 0;
  572. }
  573. }
  574. dev = le16_to_cpup((void *)&buf[0]);
  575. adr = le16_to_cpup((void *)&buf[2]);
  576. opt = le16_to_cpup((void *)&buf[4]);
  577. len = le16_to_cpup((void *)&buf[6]);
  578. if (!(opt & BIT_0))
  579. if (len == 0 || len > DMA_POOL_SIZE)
  580. return -EINVAL;
  581. memset(ha->edc_data, 0, len);
  582. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  583. ha->edc_data, len, opt);
  584. if (rval != QLA_SUCCESS) {
  585. DEBUG2(qla_printk(KERN_INFO, ha,
  586. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  587. rval, dev, adr, opt, len));
  588. return 0;
  589. }
  590. ha->edc_data_len = len;
  591. return count;
  592. }
  593. static ssize_t
  594. qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
  595. struct bin_attribute *bin_attr,
  596. char *buf, loff_t off, size_t count)
  597. {
  598. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  599. struct device, kobj)));
  600. struct qla_hw_data *ha = vha->hw;
  601. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  602. return 0;
  603. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  604. return -EINVAL;
  605. memcpy(buf, ha->edc_data, ha->edc_data_len);
  606. return ha->edc_data_len;
  607. }
  608. static struct bin_attribute sysfs_edc_status_attr = {
  609. .attr = {
  610. .name = "edc_status",
  611. .mode = S_IRUSR | S_IWUSR,
  612. },
  613. .size = 0,
  614. .write = qla2x00_sysfs_write_edc_status,
  615. .read = qla2x00_sysfs_read_edc_status,
  616. };
  617. static ssize_t
  618. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  619. struct bin_attribute *bin_attr,
  620. char *buf, loff_t off, size_t count)
  621. {
  622. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  623. struct device, kobj)));
  624. struct qla_hw_data *ha = vha->hw;
  625. int rval;
  626. uint16_t actual_size;
  627. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  628. return 0;
  629. if (ha->xgmac_data)
  630. goto do_read;
  631. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  632. &ha->xgmac_data_dma, GFP_KERNEL);
  633. if (!ha->xgmac_data) {
  634. qla_printk(KERN_WARNING, ha,
  635. "Unable to allocate memory for XGMAC read-data.\n");
  636. return 0;
  637. }
  638. do_read:
  639. actual_size = 0;
  640. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  641. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  642. XGMAC_DATA_SIZE, &actual_size);
  643. if (rval != QLA_SUCCESS) {
  644. qla_printk(KERN_WARNING, ha,
  645. "Unable to read XGMAC data (%x).\n", rval);
  646. count = 0;
  647. }
  648. count = actual_size > count ? count: actual_size;
  649. memcpy(buf, ha->xgmac_data, count);
  650. return count;
  651. }
  652. static struct bin_attribute sysfs_xgmac_stats_attr = {
  653. .attr = {
  654. .name = "xgmac_stats",
  655. .mode = S_IRUSR,
  656. },
  657. .size = 0,
  658. .read = qla2x00_sysfs_read_xgmac_stats,
  659. };
  660. static ssize_t
  661. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  662. struct bin_attribute *bin_attr,
  663. char *buf, loff_t off, size_t count)
  664. {
  665. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  666. struct device, kobj)));
  667. struct qla_hw_data *ha = vha->hw;
  668. int rval;
  669. uint16_t actual_size;
  670. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  671. return 0;
  672. if (ha->dcbx_tlv)
  673. goto do_read;
  674. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  675. &ha->dcbx_tlv_dma, GFP_KERNEL);
  676. if (!ha->dcbx_tlv) {
  677. qla_printk(KERN_WARNING, ha,
  678. "Unable to allocate memory for DCBX TLV read-data.\n");
  679. return 0;
  680. }
  681. do_read:
  682. actual_size = 0;
  683. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  684. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  685. DCBX_TLV_DATA_SIZE);
  686. if (rval != QLA_SUCCESS) {
  687. qla_printk(KERN_WARNING, ha,
  688. "Unable to read DCBX TLV data (%x).\n", rval);
  689. count = 0;
  690. }
  691. memcpy(buf, ha->dcbx_tlv, count);
  692. return count;
  693. }
  694. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  695. .attr = {
  696. .name = "dcbx_tlv",
  697. .mode = S_IRUSR,
  698. },
  699. .size = 0,
  700. .read = qla2x00_sysfs_read_dcbx_tlv,
  701. };
  702. static struct sysfs_entry {
  703. char *name;
  704. struct bin_attribute *attr;
  705. int is4GBp_only;
  706. } bin_file_entries[] = {
  707. { "fw_dump", &sysfs_fw_dump_attr, },
  708. { "nvram", &sysfs_nvram_attr, },
  709. { "optrom", &sysfs_optrom_attr, },
  710. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  711. { "vpd", &sysfs_vpd_attr, 1 },
  712. { "sfp", &sysfs_sfp_attr, 1 },
  713. { "reset", &sysfs_reset_attr, },
  714. { "edc", &sysfs_edc_attr, 2 },
  715. { "edc_status", &sysfs_edc_status_attr, 2 },
  716. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  717. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  718. { NULL },
  719. };
  720. void
  721. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  722. {
  723. struct Scsi_Host *host = vha->host;
  724. struct sysfs_entry *iter;
  725. int ret;
  726. for (iter = bin_file_entries; iter->name; iter++) {
  727. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  728. continue;
  729. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  730. continue;
  731. if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
  732. continue;
  733. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  734. iter->attr);
  735. if (ret)
  736. qla_printk(KERN_INFO, vha->hw,
  737. "Unable to create sysfs %s binary attribute "
  738. "(%d).\n", iter->name, ret);
  739. }
  740. }
  741. void
  742. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  743. {
  744. struct Scsi_Host *host = vha->host;
  745. struct sysfs_entry *iter;
  746. struct qla_hw_data *ha = vha->hw;
  747. for (iter = bin_file_entries; iter->name; iter++) {
  748. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  749. continue;
  750. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  751. continue;
  752. if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
  753. continue;
  754. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  755. iter->attr);
  756. }
  757. if (ha->beacon_blink_led == 1)
  758. ha->isp_ops->beacon_off(vha);
  759. }
  760. /* Scsi_Host attributes. */
  761. static ssize_t
  762. qla2x00_drvr_version_show(struct device *dev,
  763. struct device_attribute *attr, char *buf)
  764. {
  765. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  766. }
  767. static ssize_t
  768. qla2x00_fw_version_show(struct device *dev,
  769. struct device_attribute *attr, char *buf)
  770. {
  771. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  772. struct qla_hw_data *ha = vha->hw;
  773. char fw_str[128];
  774. return snprintf(buf, PAGE_SIZE, "%s\n",
  775. ha->isp_ops->fw_version_str(vha, fw_str));
  776. }
  777. static ssize_t
  778. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  779. char *buf)
  780. {
  781. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  782. struct qla_hw_data *ha = vha->hw;
  783. uint32_t sn;
  784. if (IS_FWI2_CAPABLE(ha)) {
  785. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  786. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  787. }
  788. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  789. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  790. sn % 100000);
  791. }
  792. static ssize_t
  793. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  794. char *buf)
  795. {
  796. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  797. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  798. }
  799. static ssize_t
  800. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  801. char *buf)
  802. {
  803. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  804. struct qla_hw_data *ha = vha->hw;
  805. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  806. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  807. ha->product_id[3]);
  808. }
  809. static ssize_t
  810. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  811. char *buf)
  812. {
  813. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  814. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  815. }
  816. static ssize_t
  817. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  818. char *buf)
  819. {
  820. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  821. return snprintf(buf, PAGE_SIZE, "%s\n",
  822. vha->hw->model_desc ? vha->hw->model_desc : "");
  823. }
  824. static ssize_t
  825. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  826. char *buf)
  827. {
  828. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  829. char pci_info[30];
  830. return snprintf(buf, PAGE_SIZE, "%s\n",
  831. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  832. }
  833. static ssize_t
  834. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  835. char *buf)
  836. {
  837. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  838. struct qla_hw_data *ha = vha->hw;
  839. int len = 0;
  840. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  841. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  842. vha->device_flags & DFLG_NO_CABLE)
  843. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  844. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  845. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  846. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  847. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  848. else {
  849. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  850. switch (ha->current_topology) {
  851. case ISP_CFG_NL:
  852. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  853. break;
  854. case ISP_CFG_FL:
  855. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  856. break;
  857. case ISP_CFG_N:
  858. len += snprintf(buf + len, PAGE_SIZE-len,
  859. "N_Port to N_Port\n");
  860. break;
  861. case ISP_CFG_F:
  862. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  863. break;
  864. default:
  865. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  866. break;
  867. }
  868. }
  869. return len;
  870. }
  871. static ssize_t
  872. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  873. char *buf)
  874. {
  875. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  876. int len = 0;
  877. switch (vha->hw->zio_mode) {
  878. case QLA_ZIO_MODE_6:
  879. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  880. break;
  881. case QLA_ZIO_DISABLED:
  882. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  883. break;
  884. }
  885. return len;
  886. }
  887. static ssize_t
  888. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  889. const char *buf, size_t count)
  890. {
  891. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  892. struct qla_hw_data *ha = vha->hw;
  893. int val = 0;
  894. uint16_t zio_mode;
  895. if (!IS_ZIO_SUPPORTED(ha))
  896. return -ENOTSUPP;
  897. if (sscanf(buf, "%d", &val) != 1)
  898. return -EINVAL;
  899. if (val)
  900. zio_mode = QLA_ZIO_MODE_6;
  901. else
  902. zio_mode = QLA_ZIO_DISABLED;
  903. /* Update per-hba values and queue a reset. */
  904. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  905. ha->zio_mode = zio_mode;
  906. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  907. }
  908. return strlen(buf);
  909. }
  910. static ssize_t
  911. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  912. char *buf)
  913. {
  914. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  915. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  916. }
  917. static ssize_t
  918. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  919. const char *buf, size_t count)
  920. {
  921. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  922. int val = 0;
  923. uint16_t zio_timer;
  924. if (sscanf(buf, "%d", &val) != 1)
  925. return -EINVAL;
  926. if (val > 25500 || val < 100)
  927. return -ERANGE;
  928. zio_timer = (uint16_t)(val / 100);
  929. vha->hw->zio_timer = zio_timer;
  930. return strlen(buf);
  931. }
  932. static ssize_t
  933. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  934. char *buf)
  935. {
  936. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  937. int len = 0;
  938. if (vha->hw->beacon_blink_led)
  939. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  940. else
  941. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  942. return len;
  943. }
  944. static ssize_t
  945. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  946. const char *buf, size_t count)
  947. {
  948. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  949. struct qla_hw_data *ha = vha->hw;
  950. int val = 0;
  951. int rval;
  952. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  953. return -EPERM;
  954. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  955. qla_printk(KERN_WARNING, ha,
  956. "Abort ISP active -- ignoring beacon request.\n");
  957. return -EBUSY;
  958. }
  959. if (sscanf(buf, "%d", &val) != 1)
  960. return -EINVAL;
  961. if (val)
  962. rval = ha->isp_ops->beacon_on(vha);
  963. else
  964. rval = ha->isp_ops->beacon_off(vha);
  965. if (rval != QLA_SUCCESS)
  966. count = 0;
  967. return count;
  968. }
  969. static ssize_t
  970. qla2x00_optrom_bios_version_show(struct device *dev,
  971. struct device_attribute *attr, char *buf)
  972. {
  973. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  974. struct qla_hw_data *ha = vha->hw;
  975. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  976. ha->bios_revision[0]);
  977. }
  978. static ssize_t
  979. qla2x00_optrom_efi_version_show(struct device *dev,
  980. struct device_attribute *attr, char *buf)
  981. {
  982. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  983. struct qla_hw_data *ha = vha->hw;
  984. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  985. ha->efi_revision[0]);
  986. }
  987. static ssize_t
  988. qla2x00_optrom_fcode_version_show(struct device *dev,
  989. struct device_attribute *attr, char *buf)
  990. {
  991. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  992. struct qla_hw_data *ha = vha->hw;
  993. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  994. ha->fcode_revision[0]);
  995. }
  996. static ssize_t
  997. qla2x00_optrom_fw_version_show(struct device *dev,
  998. struct device_attribute *attr, char *buf)
  999. {
  1000. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1001. struct qla_hw_data *ha = vha->hw;
  1002. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1003. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1004. ha->fw_revision[3]);
  1005. }
  1006. static ssize_t
  1007. qla2x00_total_isp_aborts_show(struct device *dev,
  1008. struct device_attribute *attr, char *buf)
  1009. {
  1010. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1011. struct qla_hw_data *ha = vha->hw;
  1012. return snprintf(buf, PAGE_SIZE, "%d\n",
  1013. ha->qla_stats.total_isp_aborts);
  1014. }
  1015. static ssize_t
  1016. qla24xx_84xx_fw_version_show(struct device *dev,
  1017. struct device_attribute *attr, char *buf)
  1018. {
  1019. int rval = QLA_SUCCESS;
  1020. uint16_t status[2] = {0, 0};
  1021. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1022. struct qla_hw_data *ha = vha->hw;
  1023. if (!IS_QLA84XX(ha))
  1024. return snprintf(buf, PAGE_SIZE, "\n");
  1025. if (ha->cs84xx && ha->cs84xx->op_fw_version == 0)
  1026. rval = qla84xx_verify_chip(vha, status);
  1027. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1028. return snprintf(buf, PAGE_SIZE, "%u\n",
  1029. (uint32_t)ha->cs84xx->op_fw_version);
  1030. return snprintf(buf, PAGE_SIZE, "\n");
  1031. }
  1032. static ssize_t
  1033. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1034. char *buf)
  1035. {
  1036. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1037. struct qla_hw_data *ha = vha->hw;
  1038. if (!IS_QLA81XX(ha))
  1039. return snprintf(buf, PAGE_SIZE, "\n");
  1040. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1041. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1042. ha->mpi_capabilities);
  1043. }
  1044. static ssize_t
  1045. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1046. char *buf)
  1047. {
  1048. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1049. struct qla_hw_data *ha = vha->hw;
  1050. if (!IS_QLA81XX(ha))
  1051. return snprintf(buf, PAGE_SIZE, "\n");
  1052. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1053. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1054. }
  1055. static ssize_t
  1056. qla2x00_flash_block_size_show(struct device *dev,
  1057. struct device_attribute *attr, char *buf)
  1058. {
  1059. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1060. struct qla_hw_data *ha = vha->hw;
  1061. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1062. }
  1063. static ssize_t
  1064. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1065. char *buf)
  1066. {
  1067. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1068. if (!IS_QLA8XXX_TYPE(vha->hw))
  1069. return snprintf(buf, PAGE_SIZE, "\n");
  1070. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1071. }
  1072. static ssize_t
  1073. qla2x00_vn_port_mac_address_show(struct device *dev,
  1074. struct device_attribute *attr, char *buf)
  1075. {
  1076. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1077. if (!IS_QLA8XXX_TYPE(vha->hw))
  1078. return snprintf(buf, PAGE_SIZE, "\n");
  1079. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1080. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1081. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1082. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1083. }
  1084. static ssize_t
  1085. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1086. char *buf)
  1087. {
  1088. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1089. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1090. }
  1091. static ssize_t
  1092. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1093. char *buf)
  1094. {
  1095. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1096. int rval = QLA_FUNCTION_FAILED;
  1097. uint16_t state[5];
  1098. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1099. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1100. DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
  1101. __func__, vha->host_no));
  1102. else if (!vha->hw->flags.eeh_busy)
  1103. rval = qla2x00_get_firmware_state(vha, state);
  1104. if (rval != QLA_SUCCESS)
  1105. memset(state, -1, sizeof(state));
  1106. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1107. state[1], state[2], state[3], state[4]);
  1108. }
  1109. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1110. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1111. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1112. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1113. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1114. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1115. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1116. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1117. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1118. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1119. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1120. qla2x00_zio_timer_store);
  1121. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1122. qla2x00_beacon_store);
  1123. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1124. qla2x00_optrom_bios_version_show, NULL);
  1125. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1126. qla2x00_optrom_efi_version_show, NULL);
  1127. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1128. qla2x00_optrom_fcode_version_show, NULL);
  1129. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1130. NULL);
  1131. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1132. NULL);
  1133. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1134. NULL);
  1135. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1136. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1137. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1138. NULL);
  1139. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1140. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1141. qla2x00_vn_port_mac_address_show, NULL);
  1142. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1143. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1144. struct device_attribute *qla2x00_host_attrs[] = {
  1145. &dev_attr_driver_version,
  1146. &dev_attr_fw_version,
  1147. &dev_attr_serial_num,
  1148. &dev_attr_isp_name,
  1149. &dev_attr_isp_id,
  1150. &dev_attr_model_name,
  1151. &dev_attr_model_desc,
  1152. &dev_attr_pci_info,
  1153. &dev_attr_link_state,
  1154. &dev_attr_zio,
  1155. &dev_attr_zio_timer,
  1156. &dev_attr_beacon,
  1157. &dev_attr_optrom_bios_version,
  1158. &dev_attr_optrom_efi_version,
  1159. &dev_attr_optrom_fcode_version,
  1160. &dev_attr_optrom_fw_version,
  1161. &dev_attr_84xx_fw_version,
  1162. &dev_attr_total_isp_aborts,
  1163. &dev_attr_mpi_version,
  1164. &dev_attr_phy_version,
  1165. &dev_attr_flash_block_size,
  1166. &dev_attr_vlan_id,
  1167. &dev_attr_vn_port_mac_address,
  1168. &dev_attr_fabric_param,
  1169. &dev_attr_fw_state,
  1170. NULL,
  1171. };
  1172. /* Host attributes. */
  1173. static void
  1174. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1175. {
  1176. scsi_qla_host_t *vha = shost_priv(shost);
  1177. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1178. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1179. }
  1180. static void
  1181. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1182. {
  1183. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1184. (shost_priv(shost)))->hw;
  1185. u32 speed = FC_PORTSPEED_UNKNOWN;
  1186. switch (ha->link_data_rate) {
  1187. case PORT_SPEED_1GB:
  1188. speed = FC_PORTSPEED_1GBIT;
  1189. break;
  1190. case PORT_SPEED_2GB:
  1191. speed = FC_PORTSPEED_2GBIT;
  1192. break;
  1193. case PORT_SPEED_4GB:
  1194. speed = FC_PORTSPEED_4GBIT;
  1195. break;
  1196. case PORT_SPEED_8GB:
  1197. speed = FC_PORTSPEED_8GBIT;
  1198. break;
  1199. case PORT_SPEED_10GB:
  1200. speed = FC_PORTSPEED_10GBIT;
  1201. break;
  1202. }
  1203. fc_host_speed(shost) = speed;
  1204. }
  1205. static void
  1206. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1207. {
  1208. scsi_qla_host_t *vha = shost_priv(shost);
  1209. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1210. if (vha->vp_idx) {
  1211. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1212. return;
  1213. }
  1214. switch (vha->hw->current_topology) {
  1215. case ISP_CFG_NL:
  1216. port_type = FC_PORTTYPE_LPORT;
  1217. break;
  1218. case ISP_CFG_FL:
  1219. port_type = FC_PORTTYPE_NLPORT;
  1220. break;
  1221. case ISP_CFG_N:
  1222. port_type = FC_PORTTYPE_PTP;
  1223. break;
  1224. case ISP_CFG_F:
  1225. port_type = FC_PORTTYPE_NPORT;
  1226. break;
  1227. }
  1228. fc_host_port_type(shost) = port_type;
  1229. }
  1230. static void
  1231. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1232. {
  1233. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1234. scsi_qla_host_t *vha = shost_priv(host);
  1235. fc_port_t *fcport;
  1236. u64 node_name = 0;
  1237. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1238. if (fcport->rport &&
  1239. starget->id == fcport->rport->scsi_target_id) {
  1240. node_name = wwn_to_u64(fcport->node_name);
  1241. break;
  1242. }
  1243. }
  1244. fc_starget_node_name(starget) = node_name;
  1245. }
  1246. static void
  1247. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1248. {
  1249. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1250. scsi_qla_host_t *vha = shost_priv(host);
  1251. fc_port_t *fcport;
  1252. u64 port_name = 0;
  1253. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1254. if (fcport->rport &&
  1255. starget->id == fcport->rport->scsi_target_id) {
  1256. port_name = wwn_to_u64(fcport->port_name);
  1257. break;
  1258. }
  1259. }
  1260. fc_starget_port_name(starget) = port_name;
  1261. }
  1262. static void
  1263. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1264. {
  1265. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1266. scsi_qla_host_t *vha = shost_priv(host);
  1267. fc_port_t *fcport;
  1268. uint32_t port_id = ~0U;
  1269. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1270. if (fcport->rport &&
  1271. starget->id == fcport->rport->scsi_target_id) {
  1272. port_id = fcport->d_id.b.domain << 16 |
  1273. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1274. break;
  1275. }
  1276. }
  1277. fc_starget_port_id(starget) = port_id;
  1278. }
  1279. static void
  1280. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1281. {
  1282. if (timeout)
  1283. rport->dev_loss_tmo = timeout;
  1284. else
  1285. rport->dev_loss_tmo = 1;
  1286. }
  1287. static void
  1288. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1289. {
  1290. struct Scsi_Host *host = rport_to_shost(rport);
  1291. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1292. if (!fcport)
  1293. return;
  1294. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1295. return;
  1296. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1297. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1298. return;
  1299. }
  1300. /*
  1301. * Transport has effectively 'deleted' the rport, clear
  1302. * all local references.
  1303. */
  1304. spin_lock_irq(host->host_lock);
  1305. fcport->rport = NULL;
  1306. *((fc_port_t **)rport->dd_data) = NULL;
  1307. spin_unlock_irq(host->host_lock);
  1308. }
  1309. static void
  1310. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1311. {
  1312. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1313. if (!fcport)
  1314. return;
  1315. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1316. return;
  1317. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1318. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1319. return;
  1320. }
  1321. /*
  1322. * At this point all fcport's software-states are cleared. Perform any
  1323. * final cleanup of firmware resources (PCBs and XCBs).
  1324. */
  1325. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1326. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1327. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1328. fcport->loop_id, fcport->d_id.b.domain,
  1329. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1330. }
  1331. static int
  1332. qla2x00_issue_lip(struct Scsi_Host *shost)
  1333. {
  1334. scsi_qla_host_t *vha = shost_priv(shost);
  1335. qla2x00_loop_reset(vha);
  1336. return 0;
  1337. }
  1338. static struct fc_host_statistics *
  1339. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1340. {
  1341. scsi_qla_host_t *vha = shost_priv(shost);
  1342. struct qla_hw_data *ha = vha->hw;
  1343. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1344. int rval;
  1345. struct link_statistics *stats;
  1346. dma_addr_t stats_dma;
  1347. struct fc_host_statistics *pfc_host_stat;
  1348. pfc_host_stat = &ha->fc_host_stat;
  1349. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1350. if (test_bit(UNLOADING, &vha->dpc_flags))
  1351. goto done;
  1352. if (unlikely(pci_channel_offline(ha->pdev)))
  1353. goto done;
  1354. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1355. if (stats == NULL) {
  1356. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1357. __func__, base_vha->host_no));
  1358. goto done;
  1359. }
  1360. memset(stats, 0, DMA_POOL_SIZE);
  1361. rval = QLA_FUNCTION_FAILED;
  1362. if (IS_FWI2_CAPABLE(ha)) {
  1363. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1364. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1365. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1366. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1367. !ha->dpc_active) {
  1368. /* Must be in a 'READY' state for statistics retrieval. */
  1369. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1370. stats, stats_dma);
  1371. }
  1372. if (rval != QLA_SUCCESS)
  1373. goto done_free;
  1374. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1375. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1376. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1377. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1378. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1379. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1380. if (IS_FWI2_CAPABLE(ha)) {
  1381. pfc_host_stat->lip_count = stats->lip_cnt;
  1382. pfc_host_stat->tx_frames = stats->tx_frames;
  1383. pfc_host_stat->rx_frames = stats->rx_frames;
  1384. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1385. pfc_host_stat->nos_count = stats->nos_rcvd;
  1386. }
  1387. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1388. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1389. done_free:
  1390. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1391. done:
  1392. return pfc_host_stat;
  1393. }
  1394. static void
  1395. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1396. {
  1397. scsi_qla_host_t *vha = shost_priv(shost);
  1398. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1399. }
  1400. static void
  1401. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1402. {
  1403. scsi_qla_host_t *vha = shost_priv(shost);
  1404. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1405. }
  1406. static void
  1407. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1408. {
  1409. scsi_qla_host_t *vha = shost_priv(shost);
  1410. u64 node_name;
  1411. if (vha->device_flags & SWITCH_FOUND)
  1412. node_name = wwn_to_u64(vha->fabric_node_name);
  1413. else
  1414. node_name = wwn_to_u64(vha->node_name);
  1415. fc_host_fabric_name(shost) = node_name;
  1416. }
  1417. static void
  1418. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1419. {
  1420. scsi_qla_host_t *vha = shost_priv(shost);
  1421. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1422. if (!base_vha->flags.online)
  1423. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1424. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1425. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1426. else
  1427. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1428. }
  1429. static int
  1430. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1431. {
  1432. int ret = 0;
  1433. uint8_t qos = 0;
  1434. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1435. scsi_qla_host_t *vha = NULL;
  1436. struct qla_hw_data *ha = base_vha->hw;
  1437. uint16_t options = 0;
  1438. int cnt;
  1439. struct req_que *req = ha->req_q_map[0];
  1440. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1441. if (ret) {
  1442. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1443. "status %x\n", ret));
  1444. return (ret);
  1445. }
  1446. vha = qla24xx_create_vhost(fc_vport);
  1447. if (vha == NULL) {
  1448. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1449. vha));
  1450. return FC_VPORT_FAILED;
  1451. }
  1452. if (disable) {
  1453. atomic_set(&vha->vp_state, VP_OFFLINE);
  1454. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1455. } else
  1456. atomic_set(&vha->vp_state, VP_FAILED);
  1457. /* ready to create vport */
  1458. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1459. vha->vp_idx);
  1460. /* initialized vport states */
  1461. atomic_set(&vha->loop_state, LOOP_DOWN);
  1462. vha->vp_err_state= VP_ERR_PORTDWN;
  1463. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1464. /* Check if physical ha port is Up */
  1465. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1466. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1467. /* Don't retry or attempt login of this virtual port */
  1468. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1469. base_vha->host_no));
  1470. atomic_set(&vha->loop_state, LOOP_DEAD);
  1471. if (!disable)
  1472. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1473. }
  1474. if (IS_QLA25XX(ha) && ql2xenabledif) {
  1475. if (ha->fw_attributes & BIT_4) {
  1476. vha->flags.difdix_supported = 1;
  1477. DEBUG18(qla_printk(KERN_INFO, ha,
  1478. "Registering for DIF/DIX type 1 and 3"
  1479. " protection.\n"));
  1480. scsi_host_set_prot(vha->host,
  1481. SHOST_DIF_TYPE1_PROTECTION
  1482. | SHOST_DIF_TYPE3_PROTECTION
  1483. | SHOST_DIX_TYPE1_PROTECTION
  1484. | SHOST_DIX_TYPE3_PROTECTION);
  1485. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1486. } else
  1487. vha->flags.difdix_supported = 0;
  1488. }
  1489. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1490. &ha->pdev->dev)) {
  1491. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1492. vha->host_no, vha->vp_idx));
  1493. goto vport_create_failed_2;
  1494. }
  1495. /* initialize attributes */
  1496. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1497. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1498. fc_host_supported_classes(vha->host) =
  1499. fc_host_supported_classes(base_vha->host);
  1500. fc_host_supported_speeds(vha->host) =
  1501. fc_host_supported_speeds(base_vha->host);
  1502. qla24xx_vport_disable(fc_vport, disable);
  1503. if (ha->flags.cpu_affinity_enabled) {
  1504. req = ha->req_q_map[1];
  1505. goto vport_queue;
  1506. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1507. goto vport_queue;
  1508. /* Create a request queue in QoS mode for the vport */
  1509. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1510. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1511. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1512. 8) == 0) {
  1513. qos = ha->npiv_info[cnt].q_qos;
  1514. break;
  1515. }
  1516. }
  1517. if (qos) {
  1518. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1519. qos);
  1520. if (!ret)
  1521. qla_printk(KERN_WARNING, ha,
  1522. "Can't create request queue for vp_idx:%d\n",
  1523. vha->vp_idx);
  1524. else {
  1525. DEBUG2(qla_printk(KERN_INFO, ha,
  1526. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1527. ret, qos, vha->vp_idx));
  1528. req = ha->req_q_map[ret];
  1529. }
  1530. }
  1531. vport_queue:
  1532. vha->req = req;
  1533. return 0;
  1534. vport_create_failed_2:
  1535. qla24xx_disable_vp(vha);
  1536. qla24xx_deallocate_vp_id(vha);
  1537. scsi_host_put(vha->host);
  1538. return FC_VPORT_FAILED;
  1539. }
  1540. static int
  1541. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1542. {
  1543. scsi_qla_host_t *vha = fc_vport->dd_data;
  1544. fc_port_t *fcport, *tfcport;
  1545. struct qla_hw_data *ha = vha->hw;
  1546. uint16_t id = vha->vp_idx;
  1547. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1548. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1549. msleep(1000);
  1550. qla24xx_disable_vp(vha);
  1551. fc_remove_host(vha->host);
  1552. scsi_remove_host(vha->host);
  1553. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1554. list_del(&fcport->list);
  1555. kfree(fcport);
  1556. fcport = NULL;
  1557. }
  1558. qla24xx_deallocate_vp_id(vha);
  1559. mutex_lock(&ha->vport_lock);
  1560. ha->cur_vport_count--;
  1561. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1562. mutex_unlock(&ha->vport_lock);
  1563. if (vha->timer_active) {
  1564. qla2x00_vp_stop_timer(vha);
  1565. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1566. "has stopped\n",
  1567. vha->host_no, vha->vp_idx, vha));
  1568. }
  1569. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1570. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1571. qla_printk(KERN_WARNING, ha,
  1572. "Queue delete failed.\n");
  1573. }
  1574. scsi_host_put(vha->host);
  1575. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1576. return 0;
  1577. }
  1578. static int
  1579. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1580. {
  1581. scsi_qla_host_t *vha = fc_vport->dd_data;
  1582. if (disable)
  1583. qla24xx_disable_vp(vha);
  1584. else
  1585. qla24xx_enable_vp(vha);
  1586. return 0;
  1587. }
  1588. struct fc_function_template qla2xxx_transport_functions = {
  1589. .show_host_node_name = 1,
  1590. .show_host_port_name = 1,
  1591. .show_host_supported_classes = 1,
  1592. .show_host_supported_speeds = 1,
  1593. .get_host_port_id = qla2x00_get_host_port_id,
  1594. .show_host_port_id = 1,
  1595. .get_host_speed = qla2x00_get_host_speed,
  1596. .show_host_speed = 1,
  1597. .get_host_port_type = qla2x00_get_host_port_type,
  1598. .show_host_port_type = 1,
  1599. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1600. .show_host_symbolic_name = 1,
  1601. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1602. .show_host_system_hostname = 1,
  1603. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1604. .show_host_fabric_name = 1,
  1605. .get_host_port_state = qla2x00_get_host_port_state,
  1606. .show_host_port_state = 1,
  1607. .dd_fcrport_size = sizeof(struct fc_port *),
  1608. .show_rport_supported_classes = 1,
  1609. .get_starget_node_name = qla2x00_get_starget_node_name,
  1610. .show_starget_node_name = 1,
  1611. .get_starget_port_name = qla2x00_get_starget_port_name,
  1612. .show_starget_port_name = 1,
  1613. .get_starget_port_id = qla2x00_get_starget_port_id,
  1614. .show_starget_port_id = 1,
  1615. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1616. .show_rport_dev_loss_tmo = 1,
  1617. .issue_fc_host_lip = qla2x00_issue_lip,
  1618. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1619. .terminate_rport_io = qla2x00_terminate_rport_io,
  1620. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1621. .vport_create = qla24xx_vport_create,
  1622. .vport_disable = qla24xx_vport_disable,
  1623. .vport_delete = qla24xx_vport_delete,
  1624. .bsg_request = qla24xx_bsg_request,
  1625. .bsg_timeout = qla24xx_bsg_timeout,
  1626. };
  1627. struct fc_function_template qla2xxx_transport_vport_functions = {
  1628. .show_host_node_name = 1,
  1629. .show_host_port_name = 1,
  1630. .show_host_supported_classes = 1,
  1631. .get_host_port_id = qla2x00_get_host_port_id,
  1632. .show_host_port_id = 1,
  1633. .get_host_speed = qla2x00_get_host_speed,
  1634. .show_host_speed = 1,
  1635. .get_host_port_type = qla2x00_get_host_port_type,
  1636. .show_host_port_type = 1,
  1637. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1638. .show_host_symbolic_name = 1,
  1639. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1640. .show_host_system_hostname = 1,
  1641. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1642. .show_host_fabric_name = 1,
  1643. .get_host_port_state = qla2x00_get_host_port_state,
  1644. .show_host_port_state = 1,
  1645. .dd_fcrport_size = sizeof(struct fc_port *),
  1646. .show_rport_supported_classes = 1,
  1647. .get_starget_node_name = qla2x00_get_starget_node_name,
  1648. .show_starget_node_name = 1,
  1649. .get_starget_port_name = qla2x00_get_starget_port_name,
  1650. .show_starget_port_name = 1,
  1651. .get_starget_port_id = qla2x00_get_starget_port_id,
  1652. .show_starget_port_id = 1,
  1653. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1654. .show_rport_dev_loss_tmo = 1,
  1655. .issue_fc_host_lip = qla2x00_issue_lip,
  1656. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1657. .terminate_rport_io = qla2x00_terminate_rport_io,
  1658. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1659. .bsg_request = qla24xx_bsg_request,
  1660. .bsg_timeout = qla24xx_bsg_timeout,
  1661. };
  1662. void
  1663. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1664. {
  1665. struct qla_hw_data *ha = vha->hw;
  1666. u32 speed = FC_PORTSPEED_UNKNOWN;
  1667. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1668. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1669. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1670. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1671. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1672. if (IS_QLA8XXX_TYPE(ha))
  1673. speed = FC_PORTSPEED_10GBIT;
  1674. else if (IS_QLA25XX(ha))
  1675. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1676. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1677. else if (IS_QLA24XX_TYPE(ha))
  1678. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1679. FC_PORTSPEED_1GBIT;
  1680. else if (IS_QLA23XX(ha))
  1681. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1682. else
  1683. speed = FC_PORTSPEED_1GBIT;
  1684. fc_host_supported_speeds(vha->host) = speed;
  1685. }