qla_attr.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638
  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. static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  13. int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
  14. static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  15. /* SYSFS attributes --------------------------------------------------------- */
  16. static ssize_t
  17. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  18. struct bin_attribute *bin_attr,
  19. char *buf, loff_t off, size_t count)
  20. {
  21. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  22. struct device, kobj)));
  23. struct qla_hw_data *ha = vha->hw;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  27. ha->fw_dump_len);
  28. }
  29. static ssize_t
  30. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  31. struct bin_attribute *bin_attr,
  32. char *buf, loff_t off, size_t count)
  33. {
  34. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  35. struct device, kobj)));
  36. struct qla_hw_data *ha = vha->hw;
  37. int reading;
  38. if (off != 0)
  39. return (0);
  40. reading = simple_strtol(buf, NULL, 10);
  41. switch (reading) {
  42. case 0:
  43. if (!ha->fw_dump_reading)
  44. break;
  45. qla_printk(KERN_INFO, ha,
  46. "Firmware dump cleared on (%ld).\n", vha->host_no);
  47. ha->fw_dump_reading = 0;
  48. ha->fw_dumped = 0;
  49. break;
  50. case 1:
  51. if (ha->fw_dumped && !ha->fw_dump_reading) {
  52. ha->fw_dump_reading = 1;
  53. qla_printk(KERN_INFO, ha,
  54. "Raw firmware dump ready for read on (%ld).\n",
  55. vha->host_no);
  56. }
  57. break;
  58. case 2:
  59. qla2x00_alloc_fw_dump(vha);
  60. break;
  61. case 3:
  62. qla2x00_system_error(vha);
  63. break;
  64. }
  65. return (count);
  66. }
  67. static struct bin_attribute sysfs_fw_dump_attr = {
  68. .attr = {
  69. .name = "fw_dump",
  70. .mode = S_IRUSR | S_IWUSR,
  71. },
  72. .size = 0,
  73. .read = qla2x00_sysfs_read_fw_dump,
  74. .write = qla2x00_sysfs_write_fw_dump,
  75. };
  76. static ssize_t
  77. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  78. struct bin_attribute *bin_attr,
  79. char *buf, loff_t off, size_t count)
  80. {
  81. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  82. struct device, kobj)));
  83. struct qla_hw_data *ha = vha->hw;
  84. if (!capable(CAP_SYS_ADMIN))
  85. return 0;
  86. if (IS_NOCACHE_VPD_TYPE(ha))
  87. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  88. ha->nvram_size);
  89. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  90. ha->nvram_size);
  91. }
  92. static ssize_t
  93. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  94. struct bin_attribute *bin_attr,
  95. char *buf, loff_t off, size_t count)
  96. {
  97. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  98. struct device, kobj)));
  99. struct qla_hw_data *ha = vha->hw;
  100. uint16_t cnt;
  101. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  102. !ha->isp_ops->write_nvram)
  103. return 0;
  104. /* Checksum NVRAM. */
  105. if (IS_FWI2_CAPABLE(ha)) {
  106. uint32_t *iter;
  107. uint32_t chksum;
  108. iter = (uint32_t *)buf;
  109. chksum = 0;
  110. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  111. chksum += le32_to_cpu(*iter++);
  112. chksum = ~chksum + 1;
  113. *iter = cpu_to_le32(chksum);
  114. } else {
  115. uint8_t *iter;
  116. uint8_t chksum;
  117. iter = (uint8_t *)buf;
  118. chksum = 0;
  119. for (cnt = 0; cnt < count - 1; cnt++)
  120. chksum += *iter++;
  121. chksum = ~chksum + 1;
  122. *iter = chksum;
  123. }
  124. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  125. qla_printk(KERN_WARNING, ha,
  126. "HBA not online, failing NVRAM update.\n");
  127. return -EAGAIN;
  128. }
  129. /* Write NVRAM. */
  130. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  131. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  132. count);
  133. /* NVRAM settings take effect immediately. */
  134. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  135. qla2xxx_wake_dpc(vha);
  136. qla2x00_wait_for_chip_reset(vha);
  137. return (count);
  138. }
  139. static struct bin_attribute sysfs_nvram_attr = {
  140. .attr = {
  141. .name = "nvram",
  142. .mode = S_IRUSR | S_IWUSR,
  143. },
  144. .size = 512,
  145. .read = qla2x00_sysfs_read_nvram,
  146. .write = qla2x00_sysfs_write_nvram,
  147. };
  148. static ssize_t
  149. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  150. struct bin_attribute *bin_attr,
  151. char *buf, loff_t off, size_t count)
  152. {
  153. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  154. struct device, kobj)));
  155. struct qla_hw_data *ha = vha->hw;
  156. if (ha->optrom_state != QLA_SREADING)
  157. return 0;
  158. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  159. ha->optrom_region_size);
  160. }
  161. static ssize_t
  162. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  163. struct bin_attribute *bin_attr,
  164. char *buf, loff_t off, size_t count)
  165. {
  166. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  167. struct device, kobj)));
  168. struct qla_hw_data *ha = vha->hw;
  169. if (ha->optrom_state != QLA_SWRITING)
  170. return -EINVAL;
  171. if (off > ha->optrom_region_size)
  172. return -ERANGE;
  173. if (off + count > ha->optrom_region_size)
  174. count = ha->optrom_region_size - off;
  175. memcpy(&ha->optrom_buffer[off], buf, count);
  176. return count;
  177. }
  178. static struct bin_attribute sysfs_optrom_attr = {
  179. .attr = {
  180. .name = "optrom",
  181. .mode = S_IRUSR | S_IWUSR,
  182. },
  183. .size = 0,
  184. .read = qla2x00_sysfs_read_optrom,
  185. .write = qla2x00_sysfs_write_optrom,
  186. };
  187. static ssize_t
  188. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  189. struct bin_attribute *bin_attr,
  190. char *buf, loff_t off, size_t count)
  191. {
  192. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  193. struct device, kobj)));
  194. struct qla_hw_data *ha = vha->hw;
  195. uint32_t start = 0;
  196. uint32_t size = ha->optrom_size;
  197. int val, valid;
  198. if (off)
  199. return 0;
  200. if (unlikely(pci_channel_offline(ha->pdev)))
  201. return 0;
  202. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  203. return -EINVAL;
  204. if (start > ha->optrom_size)
  205. return -EINVAL;
  206. switch (val) {
  207. case 0:
  208. if (ha->optrom_state != QLA_SREADING &&
  209. ha->optrom_state != QLA_SWRITING)
  210. break;
  211. ha->optrom_state = QLA_SWAITING;
  212. DEBUG2(qla_printk(KERN_INFO, ha,
  213. "Freeing flash region allocation -- 0x%x bytes.\n",
  214. ha->optrom_region_size));
  215. vfree(ha->optrom_buffer);
  216. ha->optrom_buffer = NULL;
  217. break;
  218. case 1:
  219. if (ha->optrom_state != QLA_SWAITING)
  220. break;
  221. ha->optrom_region_start = start;
  222. ha->optrom_region_size = start + size > ha->optrom_size ?
  223. ha->optrom_size - start : size;
  224. ha->optrom_state = QLA_SREADING;
  225. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  226. if (ha->optrom_buffer == NULL) {
  227. qla_printk(KERN_WARNING, ha,
  228. "Unable to allocate memory for optrom retrieval "
  229. "(%x).\n", ha->optrom_region_size);
  230. ha->optrom_state = QLA_SWAITING;
  231. return count;
  232. }
  233. DEBUG2(qla_printk(KERN_INFO, ha,
  234. "Reading flash region -- 0x%x/0x%x.\n",
  235. ha->optrom_region_start, ha->optrom_region_size));
  236. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  237. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  238. ha->optrom_region_start, ha->optrom_region_size);
  239. break;
  240. case 2:
  241. if (ha->optrom_state != QLA_SWAITING)
  242. break;
  243. /*
  244. * We need to be more restrictive on which FLASH regions are
  245. * allowed to be updated via user-space. Regions accessible
  246. * via this method include:
  247. *
  248. * ISP21xx/ISP22xx/ISP23xx type boards:
  249. *
  250. * 0x000000 -> 0x020000 -- Boot code.
  251. *
  252. * ISP2322/ISP24xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. *
  257. * ISP25xx type boards:
  258. *
  259. * 0x000000 -> 0x07ffff -- Boot code.
  260. * 0x080000 -> 0x0fffff -- Firmware.
  261. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  262. */
  263. valid = 0;
  264. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  265. valid = 1;
  266. else if (start == (ha->flt_region_boot * 4) ||
  267. start == (ha->flt_region_fw * 4))
  268. valid = 1;
  269. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  270. valid = 1;
  271. if (!valid) {
  272. qla_printk(KERN_WARNING, ha,
  273. "Invalid start region 0x%x/0x%x.\n", start, size);
  274. return -EINVAL;
  275. }
  276. ha->optrom_region_start = start;
  277. ha->optrom_region_size = start + size > ha->optrom_size ?
  278. ha->optrom_size - start : size;
  279. ha->optrom_state = QLA_SWRITING;
  280. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  281. if (ha->optrom_buffer == NULL) {
  282. qla_printk(KERN_WARNING, ha,
  283. "Unable to allocate memory for optrom update "
  284. "(%x).\n", ha->optrom_region_size);
  285. ha->optrom_state = QLA_SWAITING;
  286. return count;
  287. }
  288. DEBUG2(qla_printk(KERN_INFO, ha,
  289. "Staging flash region write -- 0x%x/0x%x.\n",
  290. ha->optrom_region_start, ha->optrom_region_size));
  291. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  292. break;
  293. case 3:
  294. if (ha->optrom_state != QLA_SWRITING)
  295. break;
  296. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  297. qla_printk(KERN_WARNING, ha,
  298. "HBA not online, failing flash update.\n");
  299. return -EAGAIN;
  300. }
  301. DEBUG2(qla_printk(KERN_INFO, ha,
  302. "Writing flash region -- 0x%x/0x%x.\n",
  303. ha->optrom_region_start, ha->optrom_region_size));
  304. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  305. ha->optrom_region_start, ha->optrom_region_size);
  306. break;
  307. default:
  308. count = -EINVAL;
  309. }
  310. return count;
  311. }
  312. static struct bin_attribute sysfs_optrom_ctl_attr = {
  313. .attr = {
  314. .name = "optrom_ctl",
  315. .mode = S_IWUSR,
  316. },
  317. .size = 0,
  318. .write = qla2x00_sysfs_write_optrom_ctl,
  319. };
  320. static ssize_t
  321. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  322. struct bin_attribute *bin_attr,
  323. char *buf, loff_t off, size_t count)
  324. {
  325. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  326. struct device, kobj)));
  327. struct qla_hw_data *ha = vha->hw;
  328. if (unlikely(pci_channel_offline(ha->pdev)))
  329. return 0;
  330. if (!capable(CAP_SYS_ADMIN))
  331. return 0;
  332. if (IS_NOCACHE_VPD_TYPE(ha))
  333. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  334. ha->vpd_size);
  335. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  336. }
  337. static ssize_t
  338. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  339. struct bin_attribute *bin_attr,
  340. char *buf, loff_t off, size_t count)
  341. {
  342. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  343. struct device, kobj)));
  344. struct qla_hw_data *ha = vha->hw;
  345. uint8_t *tmp_data;
  346. if (unlikely(pci_channel_offline(ha->pdev)))
  347. return 0;
  348. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  349. !ha->isp_ops->write_nvram)
  350. return 0;
  351. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  352. qla_printk(KERN_WARNING, ha,
  353. "HBA not online, failing VPD update.\n");
  354. return -EAGAIN;
  355. }
  356. /* Write NVRAM. */
  357. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  358. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  359. /* Update flash version information for 4Gb & above. */
  360. if (!IS_FWI2_CAPABLE(ha))
  361. goto done;
  362. tmp_data = vmalloc(256);
  363. if (!tmp_data) {
  364. qla_printk(KERN_WARNING, ha,
  365. "Unable to allocate memory for VPD information update.\n");
  366. goto done;
  367. }
  368. ha->isp_ops->get_flash_version(vha, tmp_data);
  369. vfree(tmp_data);
  370. done:
  371. return count;
  372. }
  373. static struct bin_attribute sysfs_vpd_attr = {
  374. .attr = {
  375. .name = "vpd",
  376. .mode = S_IRUSR | S_IWUSR,
  377. },
  378. .size = 0,
  379. .read = qla2x00_sysfs_read_vpd,
  380. .write = qla2x00_sysfs_write_vpd,
  381. };
  382. static ssize_t
  383. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  384. struct bin_attribute *bin_attr,
  385. char *buf, loff_t off, size_t count)
  386. {
  387. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  388. struct device, kobj)));
  389. struct qla_hw_data *ha = vha->hw;
  390. uint16_t iter, addr, offset;
  391. int rval;
  392. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  393. return 0;
  394. if (ha->sfp_data)
  395. goto do_read;
  396. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  397. &ha->sfp_data_dma);
  398. if (!ha->sfp_data) {
  399. qla_printk(KERN_WARNING, ha,
  400. "Unable to allocate memory for SFP read-data.\n");
  401. return 0;
  402. }
  403. do_read:
  404. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  405. addr = 0xa0;
  406. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  407. iter++, offset += SFP_BLOCK_SIZE) {
  408. if (iter == 4) {
  409. /* Skip to next device address. */
  410. addr = 0xa2;
  411. offset = 0;
  412. }
  413. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  414. SFP_BLOCK_SIZE);
  415. if (rval != QLA_SUCCESS) {
  416. qla_printk(KERN_WARNING, ha,
  417. "Unable to read SFP data (%x/%x/%x).\n", rval,
  418. addr, offset);
  419. count = 0;
  420. break;
  421. }
  422. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  423. buf += SFP_BLOCK_SIZE;
  424. }
  425. return count;
  426. }
  427. static struct bin_attribute sysfs_sfp_attr = {
  428. .attr = {
  429. .name = "sfp",
  430. .mode = S_IRUSR | S_IWUSR,
  431. },
  432. .size = SFP_DEV_SIZE * 2,
  433. .read = qla2x00_sysfs_read_sfp,
  434. };
  435. static ssize_t
  436. qla2x00_sysfs_write_reset(struct kobject *kobj,
  437. struct bin_attribute *bin_attr,
  438. char *buf, loff_t off, size_t count)
  439. {
  440. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  441. struct device, kobj)));
  442. struct qla_hw_data *ha = vha->hw;
  443. int type;
  444. if (off != 0)
  445. return 0;
  446. type = simple_strtol(buf, NULL, 10);
  447. switch (type) {
  448. case 0x2025c:
  449. qla_printk(KERN_INFO, ha,
  450. "Issuing ISP reset on (%ld).\n", vha->host_no);
  451. scsi_block_requests(vha->host);
  452. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  453. qla2xxx_wake_dpc(vha);
  454. qla2x00_wait_for_chip_reset(vha);
  455. scsi_unblock_requests(vha->host);
  456. break;
  457. case 0x2025d:
  458. if (!IS_QLA81XX(ha))
  459. break;
  460. qla_printk(KERN_INFO, ha,
  461. "Issuing MPI reset on (%ld).\n", vha->host_no);
  462. /* Make sure FC side is not in reset */
  463. qla2x00_wait_for_hba_online(vha);
  464. /* Issue MPI reset */
  465. scsi_block_requests(vha->host);
  466. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  467. qla_printk(KERN_WARNING, ha,
  468. "MPI reset failed on (%ld).\n", vha->host_no);
  469. scsi_unblock_requests(vha->host);
  470. break;
  471. }
  472. return count;
  473. }
  474. static struct bin_attribute sysfs_reset_attr = {
  475. .attr = {
  476. .name = "reset",
  477. .mode = S_IWUSR,
  478. },
  479. .size = 0,
  480. .write = qla2x00_sysfs_write_reset,
  481. };
  482. static ssize_t
  483. qla2x00_sysfs_write_edc(struct kobject *kobj,
  484. struct bin_attribute *bin_attr,
  485. char *buf, loff_t off, size_t count)
  486. {
  487. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  488. struct device, kobj)));
  489. struct qla_hw_data *ha = vha->hw;
  490. uint16_t dev, adr, opt, len;
  491. int rval;
  492. ha->edc_data_len = 0;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  494. return 0;
  495. if (!ha->edc_data) {
  496. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  497. &ha->edc_data_dma);
  498. if (!ha->edc_data) {
  499. DEBUG2(qla_printk(KERN_INFO, ha,
  500. "Unable to allocate memory for EDC write.\n"));
  501. return 0;
  502. }
  503. }
  504. dev = le16_to_cpup((void *)&buf[0]);
  505. adr = le16_to_cpup((void *)&buf[2]);
  506. opt = le16_to_cpup((void *)&buf[4]);
  507. len = le16_to_cpup((void *)&buf[6]);
  508. if (!(opt & BIT_0))
  509. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  510. return -EINVAL;
  511. memcpy(ha->edc_data, &buf[8], len);
  512. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  513. ha->edc_data, len, opt);
  514. if (rval != QLA_SUCCESS) {
  515. DEBUG2(qla_printk(KERN_INFO, ha,
  516. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  517. rval, dev, adr, opt, len, *buf));
  518. return 0;
  519. }
  520. return count;
  521. }
  522. static struct bin_attribute sysfs_edc_attr = {
  523. .attr = {
  524. .name = "edc",
  525. .mode = S_IWUSR,
  526. },
  527. .size = 0,
  528. .write = qla2x00_sysfs_write_edc,
  529. };
  530. static ssize_t
  531. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  532. struct bin_attribute *bin_attr,
  533. char *buf, loff_t off, size_t count)
  534. {
  535. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  536. struct device, kobj)));
  537. struct qla_hw_data *ha = vha->hw;
  538. uint16_t dev, adr, opt, len;
  539. int rval;
  540. ha->edc_data_len = 0;
  541. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  542. return 0;
  543. if (!ha->edc_data) {
  544. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  545. &ha->edc_data_dma);
  546. if (!ha->edc_data) {
  547. DEBUG2(qla_printk(KERN_INFO, ha,
  548. "Unable to allocate memory for EDC status.\n"));
  549. return 0;
  550. }
  551. }
  552. dev = le16_to_cpup((void *)&buf[0]);
  553. adr = le16_to_cpup((void *)&buf[2]);
  554. opt = le16_to_cpup((void *)&buf[4]);
  555. len = le16_to_cpup((void *)&buf[6]);
  556. if (!(opt & BIT_0))
  557. if (len == 0 || len > DMA_POOL_SIZE)
  558. return -EINVAL;
  559. memset(ha->edc_data, 0, len);
  560. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  561. ha->edc_data, len, opt);
  562. if (rval != QLA_SUCCESS) {
  563. DEBUG2(qla_printk(KERN_INFO, ha,
  564. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  565. rval, dev, adr, opt, len));
  566. return 0;
  567. }
  568. ha->edc_data_len = len;
  569. return count;
  570. }
  571. static ssize_t
  572. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  573. struct bin_attribute *bin_attr,
  574. char *buf, loff_t off, size_t count)
  575. {
  576. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  577. struct device, kobj)));
  578. struct qla_hw_data *ha = vha->hw;
  579. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  580. return 0;
  581. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  582. return -EINVAL;
  583. memcpy(buf, ha->edc_data, ha->edc_data_len);
  584. return ha->edc_data_len;
  585. }
  586. static struct bin_attribute sysfs_edc_status_attr = {
  587. .attr = {
  588. .name = "edc_status",
  589. .mode = S_IRUSR | S_IWUSR,
  590. },
  591. .size = 0,
  592. .write = qla2x00_sysfs_write_edc_status,
  593. .read = qla2x00_sysfs_read_edc_status,
  594. };
  595. static ssize_t
  596. qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
  597. struct bin_attribute *bin_attr,
  598. char *buf, loff_t off, size_t count)
  599. {
  600. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  601. struct device, kobj)));
  602. struct qla_hw_data *ha = vha->hw;
  603. int rval;
  604. uint16_t actual_size;
  605. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  606. return 0;
  607. if (ha->xgmac_data)
  608. goto do_read;
  609. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  610. &ha->xgmac_data_dma, GFP_KERNEL);
  611. if (!ha->xgmac_data) {
  612. qla_printk(KERN_WARNING, ha,
  613. "Unable to allocate memory for XGMAC read-data.\n");
  614. return 0;
  615. }
  616. do_read:
  617. actual_size = 0;
  618. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  619. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  620. XGMAC_DATA_SIZE, &actual_size);
  621. if (rval != QLA_SUCCESS) {
  622. qla_printk(KERN_WARNING, ha,
  623. "Unable to read XGMAC data (%x).\n", rval);
  624. count = 0;
  625. }
  626. count = actual_size > count ? count: actual_size;
  627. memcpy(buf, ha->xgmac_data, count);
  628. return count;
  629. }
  630. static struct bin_attribute sysfs_xgmac_stats_attr = {
  631. .attr = {
  632. .name = "xgmac_stats",
  633. .mode = S_IRUSR,
  634. },
  635. .size = 0,
  636. .read = qla2x00_sysfs_read_xgmac_stats,
  637. };
  638. static ssize_t
  639. qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
  640. struct bin_attribute *bin_attr,
  641. char *buf, loff_t off, size_t count)
  642. {
  643. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  644. struct device, kobj)));
  645. struct qla_hw_data *ha = vha->hw;
  646. int rval;
  647. uint16_t actual_size;
  648. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  649. return 0;
  650. if (ha->dcbx_tlv)
  651. goto do_read;
  652. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  653. &ha->dcbx_tlv_dma, GFP_KERNEL);
  654. if (!ha->dcbx_tlv) {
  655. qla_printk(KERN_WARNING, ha,
  656. "Unable to allocate memory for DCBX TLV read-data.\n");
  657. return 0;
  658. }
  659. do_read:
  660. actual_size = 0;
  661. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  662. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  663. DCBX_TLV_DATA_SIZE);
  664. if (rval != QLA_SUCCESS) {
  665. qla_printk(KERN_WARNING, ha,
  666. "Unable to read DCBX TLV data (%x).\n", rval);
  667. count = 0;
  668. }
  669. memcpy(buf, ha->dcbx_tlv, count);
  670. return count;
  671. }
  672. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  673. .attr = {
  674. .name = "dcbx_tlv",
  675. .mode = S_IRUSR,
  676. },
  677. .size = 0,
  678. .read = qla2x00_sysfs_read_dcbx_tlv,
  679. };
  680. static struct sysfs_entry {
  681. char *name;
  682. struct bin_attribute *attr;
  683. int is4GBp_only;
  684. } bin_file_entries[] = {
  685. { "fw_dump", &sysfs_fw_dump_attr, },
  686. { "nvram", &sysfs_nvram_attr, },
  687. { "optrom", &sysfs_optrom_attr, },
  688. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  689. { "vpd", &sysfs_vpd_attr, 1 },
  690. { "sfp", &sysfs_sfp_attr, 1 },
  691. { "reset", &sysfs_reset_attr, },
  692. { "edc", &sysfs_edc_attr, 2 },
  693. { "edc_status", &sysfs_edc_status_attr, 2 },
  694. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  695. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  696. { NULL },
  697. };
  698. void
  699. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  700. {
  701. struct Scsi_Host *host = vha->host;
  702. struct sysfs_entry *iter;
  703. int ret;
  704. for (iter = bin_file_entries; iter->name; iter++) {
  705. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  706. continue;
  707. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  708. continue;
  709. if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
  710. continue;
  711. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  712. iter->attr);
  713. if (ret)
  714. qla_printk(KERN_INFO, vha->hw,
  715. "Unable to create sysfs %s binary attribute "
  716. "(%d).\n", iter->name, ret);
  717. }
  718. }
  719. void
  720. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  721. {
  722. struct Scsi_Host *host = vha->host;
  723. struct sysfs_entry *iter;
  724. struct qla_hw_data *ha = vha->hw;
  725. for (iter = bin_file_entries; iter->name; iter++) {
  726. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  727. continue;
  728. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  729. continue;
  730. if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
  731. continue;
  732. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  733. iter->attr);
  734. }
  735. if (ha->beacon_blink_led == 1)
  736. ha->isp_ops->beacon_off(vha);
  737. }
  738. /* Scsi_Host attributes. */
  739. static ssize_t
  740. qla2x00_drvr_version_show(struct device *dev,
  741. struct device_attribute *attr, char *buf)
  742. {
  743. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  744. }
  745. static ssize_t
  746. qla2x00_fw_version_show(struct device *dev,
  747. struct device_attribute *attr, char *buf)
  748. {
  749. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  750. struct qla_hw_data *ha = vha->hw;
  751. char fw_str[128];
  752. return snprintf(buf, PAGE_SIZE, "%s\n",
  753. ha->isp_ops->fw_version_str(vha, fw_str));
  754. }
  755. static ssize_t
  756. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  757. char *buf)
  758. {
  759. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  760. struct qla_hw_data *ha = vha->hw;
  761. uint32_t sn;
  762. if (IS_FWI2_CAPABLE(ha)) {
  763. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  764. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  765. }
  766. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  767. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  768. sn % 100000);
  769. }
  770. static ssize_t
  771. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  772. char *buf)
  773. {
  774. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  775. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  776. }
  777. static ssize_t
  778. qla2x00_isp_id_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. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  784. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  785. ha->product_id[3]);
  786. }
  787. static ssize_t
  788. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  793. }
  794. static ssize_t
  795. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  796. char *buf)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. return snprintf(buf, PAGE_SIZE, "%s\n",
  800. vha->hw->model_desc ? vha->hw->model_desc : "");
  801. }
  802. static ssize_t
  803. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  804. char *buf)
  805. {
  806. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  807. char pci_info[30];
  808. return snprintf(buf, PAGE_SIZE, "%s\n",
  809. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  810. }
  811. static ssize_t
  812. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  813. char *buf)
  814. {
  815. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  816. struct qla_hw_data *ha = vha->hw;
  817. int len = 0;
  818. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  819. atomic_read(&vha->loop_state) == LOOP_DEAD)
  820. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  821. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  822. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  823. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  824. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  825. else {
  826. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  827. switch (ha->current_topology) {
  828. case ISP_CFG_NL:
  829. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  830. break;
  831. case ISP_CFG_FL:
  832. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  833. break;
  834. case ISP_CFG_N:
  835. len += snprintf(buf + len, PAGE_SIZE-len,
  836. "N_Port to N_Port\n");
  837. break;
  838. case ISP_CFG_F:
  839. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  840. break;
  841. default:
  842. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  843. break;
  844. }
  845. }
  846. return len;
  847. }
  848. static ssize_t
  849. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  850. char *buf)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. int len = 0;
  854. switch (vha->hw->zio_mode) {
  855. case QLA_ZIO_MODE_6:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  857. break;
  858. case QLA_ZIO_DISABLED:
  859. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  860. break;
  861. }
  862. return len;
  863. }
  864. static ssize_t
  865. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  866. const char *buf, size_t count)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. int val = 0;
  871. uint16_t zio_mode;
  872. if (!IS_ZIO_SUPPORTED(ha))
  873. return -ENOTSUPP;
  874. if (sscanf(buf, "%d", &val) != 1)
  875. return -EINVAL;
  876. if (val)
  877. zio_mode = QLA_ZIO_MODE_6;
  878. else
  879. zio_mode = QLA_ZIO_DISABLED;
  880. /* Update per-hba values and queue a reset. */
  881. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  882. ha->zio_mode = zio_mode;
  883. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  884. }
  885. return strlen(buf);
  886. }
  887. static ssize_t
  888. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  889. char *buf)
  890. {
  891. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  892. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  893. }
  894. static ssize_t
  895. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  896. const char *buf, size_t count)
  897. {
  898. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  899. int val = 0;
  900. uint16_t zio_timer;
  901. if (sscanf(buf, "%d", &val) != 1)
  902. return -EINVAL;
  903. if (val > 25500 || val < 100)
  904. return -ERANGE;
  905. zio_timer = (uint16_t)(val / 100);
  906. vha->hw->zio_timer = zio_timer;
  907. return strlen(buf);
  908. }
  909. static ssize_t
  910. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  911. char *buf)
  912. {
  913. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  914. int len = 0;
  915. if (vha->hw->beacon_blink_led)
  916. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  917. else
  918. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  919. return len;
  920. }
  921. static ssize_t
  922. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  923. const char *buf, size_t count)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. struct qla_hw_data *ha = vha->hw;
  927. int val = 0;
  928. int rval;
  929. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  930. return -EPERM;
  931. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  932. qla_printk(KERN_WARNING, ha,
  933. "Abort ISP active -- ignoring beacon request.\n");
  934. return -EBUSY;
  935. }
  936. if (sscanf(buf, "%d", &val) != 1)
  937. return -EINVAL;
  938. if (val)
  939. rval = ha->isp_ops->beacon_on(vha);
  940. else
  941. rval = ha->isp_ops->beacon_off(vha);
  942. if (rval != QLA_SUCCESS)
  943. count = 0;
  944. return count;
  945. }
  946. static ssize_t
  947. qla2x00_optrom_bios_version_show(struct device *dev,
  948. struct device_attribute *attr, char *buf)
  949. {
  950. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  951. struct qla_hw_data *ha = vha->hw;
  952. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  953. ha->bios_revision[0]);
  954. }
  955. static ssize_t
  956. qla2x00_optrom_efi_version_show(struct device *dev,
  957. struct device_attribute *attr, char *buf)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. struct qla_hw_data *ha = vha->hw;
  961. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  962. ha->efi_revision[0]);
  963. }
  964. static ssize_t
  965. qla2x00_optrom_fcode_version_show(struct device *dev,
  966. struct device_attribute *attr, char *buf)
  967. {
  968. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  969. struct qla_hw_data *ha = vha->hw;
  970. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  971. ha->fcode_revision[0]);
  972. }
  973. static ssize_t
  974. qla2x00_optrom_fw_version_show(struct device *dev,
  975. struct device_attribute *attr, char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. struct qla_hw_data *ha = vha->hw;
  979. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  980. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  981. ha->fw_revision[3]);
  982. }
  983. static ssize_t
  984. qla2x00_total_isp_aborts_show(struct device *dev,
  985. struct device_attribute *attr, char *buf)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  988. struct qla_hw_data *ha = vha->hw;
  989. return snprintf(buf, PAGE_SIZE, "%d\n",
  990. ha->qla_stats.total_isp_aborts);
  991. }
  992. static ssize_t
  993. qla24xx_84xx_fw_version_show(struct device *dev,
  994. struct device_attribute *attr, char *buf)
  995. {
  996. int rval = QLA_SUCCESS;
  997. uint16_t status[2] = {0, 0};
  998. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  999. struct qla_hw_data *ha = vha->hw;
  1000. if (IS_QLA84XX(ha) && ha->cs84xx) {
  1001. if (ha->cs84xx->op_fw_version == 0) {
  1002. rval = qla84xx_verify_chip(vha, status);
  1003. }
  1004. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1005. return snprintf(buf, PAGE_SIZE, "%u\n",
  1006. (uint32_t)ha->cs84xx->op_fw_version);
  1007. }
  1008. return snprintf(buf, PAGE_SIZE, "\n");
  1009. }
  1010. static ssize_t
  1011. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1012. char *buf)
  1013. {
  1014. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1015. struct qla_hw_data *ha = vha->hw;
  1016. if (!IS_QLA81XX(ha))
  1017. return snprintf(buf, PAGE_SIZE, "\n");
  1018. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1019. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1020. ha->mpi_capabilities);
  1021. }
  1022. static ssize_t
  1023. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1024. char *buf)
  1025. {
  1026. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1027. struct qla_hw_data *ha = vha->hw;
  1028. if (!IS_QLA81XX(ha))
  1029. return snprintf(buf, PAGE_SIZE, "\n");
  1030. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1031. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1032. }
  1033. static ssize_t
  1034. qla2x00_flash_block_size_show(struct device *dev,
  1035. struct device_attribute *attr, char *buf)
  1036. {
  1037. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1038. struct qla_hw_data *ha = vha->hw;
  1039. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1040. }
  1041. static ssize_t
  1042. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1043. char *buf)
  1044. {
  1045. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1046. if (!IS_QLA81XX(vha->hw))
  1047. return snprintf(buf, PAGE_SIZE, "\n");
  1048. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1049. }
  1050. static ssize_t
  1051. qla2x00_vn_port_mac_address_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1055. if (!IS_QLA81XX(vha->hw))
  1056. return snprintf(buf, PAGE_SIZE, "\n");
  1057. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1058. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1059. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1060. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1061. }
  1062. static ssize_t
  1063. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1064. char *buf)
  1065. {
  1066. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1067. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1068. }
  1069. static ssize_t
  1070. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1071. char *buf)
  1072. {
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. int rval = QLA_FUNCTION_FAILED;
  1075. uint16_t state[5];
  1076. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1077. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1078. DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
  1079. __func__, vha->host_no));
  1080. else if (!vha->hw->flags.eeh_busy)
  1081. rval = qla2x00_get_firmware_state(vha, state);
  1082. if (rval != QLA_SUCCESS)
  1083. memset(state, -1, sizeof(state));
  1084. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1085. state[1], state[2], state[3], state[4]);
  1086. }
  1087. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1088. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1089. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1090. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1091. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1092. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1093. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1094. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1095. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1096. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1097. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1098. qla2x00_zio_timer_store);
  1099. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1100. qla2x00_beacon_store);
  1101. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1102. qla2x00_optrom_bios_version_show, NULL);
  1103. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1104. qla2x00_optrom_efi_version_show, NULL);
  1105. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1106. qla2x00_optrom_fcode_version_show, NULL);
  1107. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1108. NULL);
  1109. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1110. NULL);
  1111. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1112. NULL);
  1113. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1114. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1115. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1116. NULL);
  1117. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1118. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1119. qla2x00_vn_port_mac_address_show, NULL);
  1120. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1121. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1122. struct device_attribute *qla2x00_host_attrs[] = {
  1123. &dev_attr_driver_version,
  1124. &dev_attr_fw_version,
  1125. &dev_attr_serial_num,
  1126. &dev_attr_isp_name,
  1127. &dev_attr_isp_id,
  1128. &dev_attr_model_name,
  1129. &dev_attr_model_desc,
  1130. &dev_attr_pci_info,
  1131. &dev_attr_link_state,
  1132. &dev_attr_zio,
  1133. &dev_attr_zio_timer,
  1134. &dev_attr_beacon,
  1135. &dev_attr_optrom_bios_version,
  1136. &dev_attr_optrom_efi_version,
  1137. &dev_attr_optrom_fcode_version,
  1138. &dev_attr_optrom_fw_version,
  1139. &dev_attr_84xx_fw_version,
  1140. &dev_attr_total_isp_aborts,
  1141. &dev_attr_mpi_version,
  1142. &dev_attr_phy_version,
  1143. &dev_attr_flash_block_size,
  1144. &dev_attr_vlan_id,
  1145. &dev_attr_vn_port_mac_address,
  1146. &dev_attr_fabric_param,
  1147. &dev_attr_fw_state,
  1148. NULL,
  1149. };
  1150. /* Host attributes. */
  1151. static void
  1152. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1153. {
  1154. scsi_qla_host_t *vha = shost_priv(shost);
  1155. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1156. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1157. }
  1158. static void
  1159. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1160. {
  1161. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1162. (shost_priv(shost)))->hw;
  1163. u32 speed = FC_PORTSPEED_UNKNOWN;
  1164. switch (ha->link_data_rate) {
  1165. case PORT_SPEED_1GB:
  1166. speed = FC_PORTSPEED_1GBIT;
  1167. break;
  1168. case PORT_SPEED_2GB:
  1169. speed = FC_PORTSPEED_2GBIT;
  1170. break;
  1171. case PORT_SPEED_4GB:
  1172. speed = FC_PORTSPEED_4GBIT;
  1173. break;
  1174. case PORT_SPEED_8GB:
  1175. speed = FC_PORTSPEED_8GBIT;
  1176. break;
  1177. case PORT_SPEED_10GB:
  1178. speed = FC_PORTSPEED_10GBIT;
  1179. break;
  1180. }
  1181. fc_host_speed(shost) = speed;
  1182. }
  1183. static void
  1184. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1185. {
  1186. scsi_qla_host_t *vha = shost_priv(shost);
  1187. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1188. if (vha->vp_idx) {
  1189. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1190. return;
  1191. }
  1192. switch (vha->hw->current_topology) {
  1193. case ISP_CFG_NL:
  1194. port_type = FC_PORTTYPE_LPORT;
  1195. break;
  1196. case ISP_CFG_FL:
  1197. port_type = FC_PORTTYPE_NLPORT;
  1198. break;
  1199. case ISP_CFG_N:
  1200. port_type = FC_PORTTYPE_PTP;
  1201. break;
  1202. case ISP_CFG_F:
  1203. port_type = FC_PORTTYPE_NPORT;
  1204. break;
  1205. }
  1206. fc_host_port_type(shost) = port_type;
  1207. }
  1208. static void
  1209. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1210. {
  1211. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1212. scsi_qla_host_t *vha = shost_priv(host);
  1213. fc_port_t *fcport;
  1214. u64 node_name = 0;
  1215. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1216. if (fcport->rport &&
  1217. starget->id == fcport->rport->scsi_target_id) {
  1218. node_name = wwn_to_u64(fcport->node_name);
  1219. break;
  1220. }
  1221. }
  1222. fc_starget_node_name(starget) = node_name;
  1223. }
  1224. static void
  1225. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1226. {
  1227. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1228. scsi_qla_host_t *vha = shost_priv(host);
  1229. fc_port_t *fcport;
  1230. u64 port_name = 0;
  1231. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1232. if (fcport->rport &&
  1233. starget->id == fcport->rport->scsi_target_id) {
  1234. port_name = wwn_to_u64(fcport->port_name);
  1235. break;
  1236. }
  1237. }
  1238. fc_starget_port_name(starget) = port_name;
  1239. }
  1240. static void
  1241. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1242. {
  1243. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1244. scsi_qla_host_t *vha = shost_priv(host);
  1245. fc_port_t *fcport;
  1246. uint32_t port_id = ~0U;
  1247. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1248. if (fcport->rport &&
  1249. starget->id == fcport->rport->scsi_target_id) {
  1250. port_id = fcport->d_id.b.domain << 16 |
  1251. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1252. break;
  1253. }
  1254. }
  1255. fc_starget_port_id(starget) = port_id;
  1256. }
  1257. static void
  1258. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1259. {
  1260. if (timeout)
  1261. rport->dev_loss_tmo = timeout;
  1262. else
  1263. rport->dev_loss_tmo = 1;
  1264. }
  1265. static void
  1266. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1267. {
  1268. struct Scsi_Host *host = rport_to_shost(rport);
  1269. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1270. if (!fcport)
  1271. return;
  1272. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1273. return;
  1274. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1275. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1276. return;
  1277. }
  1278. /*
  1279. * Transport has effectively 'deleted' the rport, clear
  1280. * all local references.
  1281. */
  1282. spin_lock_irq(host->host_lock);
  1283. fcport->rport = NULL;
  1284. *((fc_port_t **)rport->dd_data) = NULL;
  1285. spin_unlock_irq(host->host_lock);
  1286. }
  1287. static void
  1288. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1289. {
  1290. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1291. if (!fcport)
  1292. return;
  1293. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1294. return;
  1295. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1296. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1297. return;
  1298. }
  1299. /*
  1300. * At this point all fcport's software-states are cleared. Perform any
  1301. * final cleanup of firmware resources (PCBs and XCBs).
  1302. */
  1303. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1304. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1305. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1306. fcport->loop_id, fcport->d_id.b.domain,
  1307. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1308. }
  1309. static int
  1310. qla2x00_issue_lip(struct Scsi_Host *shost)
  1311. {
  1312. scsi_qla_host_t *vha = shost_priv(shost);
  1313. qla2x00_loop_reset(vha);
  1314. return 0;
  1315. }
  1316. static struct fc_host_statistics *
  1317. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1318. {
  1319. scsi_qla_host_t *vha = shost_priv(shost);
  1320. struct qla_hw_data *ha = vha->hw;
  1321. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1322. int rval;
  1323. struct link_statistics *stats;
  1324. dma_addr_t stats_dma;
  1325. struct fc_host_statistics *pfc_host_stat;
  1326. pfc_host_stat = &ha->fc_host_stat;
  1327. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1328. if (test_bit(UNLOADING, &vha->dpc_flags))
  1329. goto done;
  1330. if (unlikely(pci_channel_offline(ha->pdev)))
  1331. goto done;
  1332. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1333. if (stats == NULL) {
  1334. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1335. __func__, base_vha->host_no));
  1336. goto done;
  1337. }
  1338. memset(stats, 0, DMA_POOL_SIZE);
  1339. rval = QLA_FUNCTION_FAILED;
  1340. if (IS_FWI2_CAPABLE(ha)) {
  1341. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1342. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1343. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1344. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1345. !ha->dpc_active) {
  1346. /* Must be in a 'READY' state for statistics retrieval. */
  1347. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1348. stats, stats_dma);
  1349. }
  1350. if (rval != QLA_SUCCESS)
  1351. goto done_free;
  1352. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1353. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1354. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1355. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1356. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1357. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1358. if (IS_FWI2_CAPABLE(ha)) {
  1359. pfc_host_stat->lip_count = stats->lip_cnt;
  1360. pfc_host_stat->tx_frames = stats->tx_frames;
  1361. pfc_host_stat->rx_frames = stats->rx_frames;
  1362. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1363. pfc_host_stat->nos_count = stats->nos_rcvd;
  1364. }
  1365. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1366. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1367. done_free:
  1368. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1369. done:
  1370. return pfc_host_stat;
  1371. }
  1372. static void
  1373. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1374. {
  1375. scsi_qla_host_t *vha = shost_priv(shost);
  1376. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1377. }
  1378. static void
  1379. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1380. {
  1381. scsi_qla_host_t *vha = shost_priv(shost);
  1382. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1383. }
  1384. static void
  1385. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1386. {
  1387. scsi_qla_host_t *vha = shost_priv(shost);
  1388. u64 node_name;
  1389. if (vha->device_flags & SWITCH_FOUND)
  1390. node_name = wwn_to_u64(vha->fabric_node_name);
  1391. else
  1392. node_name = wwn_to_u64(vha->node_name);
  1393. fc_host_fabric_name(shost) = node_name;
  1394. }
  1395. static void
  1396. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1397. {
  1398. scsi_qla_host_t *vha = shost_priv(shost);
  1399. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1400. if (!base_vha->flags.online)
  1401. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1402. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1403. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1404. else
  1405. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1406. }
  1407. static int
  1408. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1409. {
  1410. int ret = 0;
  1411. uint8_t qos = 0;
  1412. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1413. scsi_qla_host_t *vha = NULL;
  1414. struct qla_hw_data *ha = base_vha->hw;
  1415. uint16_t options = 0;
  1416. int cnt;
  1417. struct req_que *req = ha->req_q_map[0];
  1418. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1419. if (ret) {
  1420. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1421. "status %x\n", ret));
  1422. return (ret);
  1423. }
  1424. vha = qla24xx_create_vhost(fc_vport);
  1425. if (vha == NULL) {
  1426. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1427. vha));
  1428. return FC_VPORT_FAILED;
  1429. }
  1430. if (disable) {
  1431. atomic_set(&vha->vp_state, VP_OFFLINE);
  1432. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1433. } else
  1434. atomic_set(&vha->vp_state, VP_FAILED);
  1435. /* ready to create vport */
  1436. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1437. vha->vp_idx);
  1438. /* initialized vport states */
  1439. atomic_set(&vha->loop_state, LOOP_DOWN);
  1440. vha->vp_err_state= VP_ERR_PORTDWN;
  1441. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1442. /* Check if physical ha port is Up */
  1443. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1444. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1445. /* Don't retry or attempt login of this virtual port */
  1446. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1447. base_vha->host_no));
  1448. atomic_set(&vha->loop_state, LOOP_DEAD);
  1449. if (!disable)
  1450. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1451. }
  1452. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1453. &ha->pdev->dev)) {
  1454. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1455. vha->host_no, vha->vp_idx));
  1456. goto vport_create_failed_2;
  1457. }
  1458. /* initialize attributes */
  1459. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1460. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1461. fc_host_supported_classes(vha->host) =
  1462. fc_host_supported_classes(base_vha->host);
  1463. fc_host_supported_speeds(vha->host) =
  1464. fc_host_supported_speeds(base_vha->host);
  1465. qla24xx_vport_disable(fc_vport, disable);
  1466. if (ha->flags.cpu_affinity_enabled) {
  1467. req = ha->req_q_map[1];
  1468. goto vport_queue;
  1469. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1470. goto vport_queue;
  1471. /* Create a request queue in QoS mode for the vport */
  1472. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1473. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1474. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1475. 8) == 0) {
  1476. qos = ha->npiv_info[cnt].q_qos;
  1477. break;
  1478. }
  1479. }
  1480. if (qos) {
  1481. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1482. qos);
  1483. if (!ret)
  1484. qla_printk(KERN_WARNING, ha,
  1485. "Can't create request queue for vp_idx:%d\n",
  1486. vha->vp_idx);
  1487. else {
  1488. DEBUG2(qla_printk(KERN_INFO, ha,
  1489. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1490. ret, qos, vha->vp_idx));
  1491. req = ha->req_q_map[ret];
  1492. }
  1493. }
  1494. vport_queue:
  1495. vha->req = req;
  1496. return 0;
  1497. vport_create_failed_2:
  1498. qla24xx_disable_vp(vha);
  1499. qla24xx_deallocate_vp_id(vha);
  1500. scsi_host_put(vha->host);
  1501. return FC_VPORT_FAILED;
  1502. }
  1503. static int
  1504. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1505. {
  1506. scsi_qla_host_t *vha = fc_vport->dd_data;
  1507. fc_port_t *fcport, *tfcport;
  1508. struct qla_hw_data *ha = vha->hw;
  1509. uint16_t id = vha->vp_idx;
  1510. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1511. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1512. msleep(1000);
  1513. qla24xx_disable_vp(vha);
  1514. fc_remove_host(vha->host);
  1515. scsi_remove_host(vha->host);
  1516. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1517. list_del(&fcport->list);
  1518. kfree(fcport);
  1519. fcport = NULL;
  1520. }
  1521. qla24xx_deallocate_vp_id(vha);
  1522. mutex_lock(&ha->vport_lock);
  1523. ha->cur_vport_count--;
  1524. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1525. mutex_unlock(&ha->vport_lock);
  1526. if (vha->timer_active) {
  1527. qla2x00_vp_stop_timer(vha);
  1528. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1529. "has stopped\n",
  1530. vha->host_no, vha->vp_idx, vha));
  1531. }
  1532. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1533. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1534. qla_printk(KERN_WARNING, ha,
  1535. "Queue delete failed.\n");
  1536. }
  1537. scsi_host_put(vha->host);
  1538. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1539. return 0;
  1540. }
  1541. static int
  1542. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1543. {
  1544. scsi_qla_host_t *vha = fc_vport->dd_data;
  1545. if (disable)
  1546. qla24xx_disable_vp(vha);
  1547. else
  1548. qla24xx_enable_vp(vha);
  1549. return 0;
  1550. }
  1551. /* BSG support for ELS/CT pass through */
  1552. inline srb_t *
  1553. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  1554. {
  1555. srb_t *sp;
  1556. struct qla_hw_data *ha = vha->hw;
  1557. struct srb_bsg_ctx *ctx;
  1558. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  1559. if (!sp)
  1560. goto done;
  1561. ctx = kzalloc(size, GFP_KERNEL);
  1562. if (!ctx) {
  1563. mempool_free(sp, ha->srb_mempool);
  1564. goto done;
  1565. }
  1566. memset(sp, 0, sizeof(*sp));
  1567. sp->fcport = fcport;
  1568. sp->ctx = ctx;
  1569. done:
  1570. return sp;
  1571. }
  1572. static int
  1573. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  1574. {
  1575. struct fc_rport *rport;
  1576. fc_port_t *fcport;
  1577. struct Scsi_Host *host;
  1578. scsi_qla_host_t *vha;
  1579. struct qla_hw_data *ha;
  1580. srb_t *sp;
  1581. const char *type;
  1582. int req_sg_cnt, rsp_sg_cnt;
  1583. int rval = (DRIVER_ERROR << 16);
  1584. uint16_t nextlid = 0;
  1585. struct srb_bsg *els;
  1586. /* Multiple SG's are not supported for ELS requests */
  1587. if (bsg_job->request_payload.sg_cnt > 1 ||
  1588. bsg_job->reply_payload.sg_cnt > 1) {
  1589. DEBUG2(printk(KERN_INFO
  1590. "multiple SG's are not supported for ELS requests"
  1591. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  1592. bsg_job->request_payload.sg_cnt,
  1593. bsg_job->reply_payload.sg_cnt));
  1594. rval = -EPERM;
  1595. goto done;
  1596. }
  1597. /* ELS request for rport */
  1598. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1599. rport = bsg_job->rport;
  1600. fcport = *(fc_port_t **) rport->dd_data;
  1601. host = rport_to_shost(rport);
  1602. vha = shost_priv(host);
  1603. ha = vha->hw;
  1604. type = "FC_BSG_RPT_ELS";
  1605. /* make sure the rport is logged in,
  1606. * if not perform fabric login
  1607. */
  1608. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  1609. DEBUG2(qla_printk(KERN_WARNING, ha,
  1610. "failed to login port %06X for ELS passthru\n",
  1611. fcport->d_id.b24));
  1612. rval = -EIO;
  1613. goto done;
  1614. }
  1615. } else {
  1616. host = bsg_job->shost;
  1617. vha = shost_priv(host);
  1618. ha = vha->hw;
  1619. type = "FC_BSG_HST_ELS_NOLOGIN";
  1620. /* Allocate a dummy fcport structure, since functions
  1621. * preparing the IOCB and mailbox command retrieves port
  1622. * specific information from fcport structure. For Host based
  1623. * ELS commands there will be no fcport structure allocated
  1624. */
  1625. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1626. if (!fcport) {
  1627. rval = -ENOMEM;
  1628. goto done;
  1629. }
  1630. /* Initialize all required fields of fcport */
  1631. fcport->vha = vha;
  1632. fcport->vp_idx = vha->vp_idx;
  1633. fcport->d_id.b.al_pa =
  1634. bsg_job->request->rqst_data.h_els.port_id[0];
  1635. fcport->d_id.b.area =
  1636. bsg_job->request->rqst_data.h_els.port_id[1];
  1637. fcport->d_id.b.domain =
  1638. bsg_job->request->rqst_data.h_els.port_id[2];
  1639. fcport->loop_id =
  1640. (fcport->d_id.b.al_pa == 0xFD) ?
  1641. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  1642. }
  1643. if (!vha->flags.online) {
  1644. DEBUG2(qla_printk(KERN_WARNING, ha,
  1645. "host not online\n"));
  1646. rval = -EIO;
  1647. goto done;
  1648. }
  1649. req_sg_cnt =
  1650. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1651. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1652. if (!req_sg_cnt) {
  1653. rval = -ENOMEM;
  1654. goto done_free_fcport;
  1655. }
  1656. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1657. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1658. if (!rsp_sg_cnt) {
  1659. rval = -ENOMEM;
  1660. goto done_free_fcport;
  1661. }
  1662. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1663. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1664. {
  1665. DEBUG2(printk(KERN_INFO
  1666. "dma mapping resulted in different sg counts \
  1667. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1668. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1669. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1670. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1671. rval = -EAGAIN;
  1672. goto done_unmap_sg;
  1673. }
  1674. /* Alloc SRB structure */
  1675. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1676. if (!sp) {
  1677. rval = -ENOMEM;
  1678. goto done_unmap_sg;
  1679. }
  1680. els = sp->ctx;
  1681. els->ctx.type =
  1682. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  1683. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  1684. els->bsg_job = bsg_job;
  1685. DEBUG2(qla_printk(KERN_INFO, ha,
  1686. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1687. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1688. bsg_job->request->rqst_data.h_els.command_code,
  1689. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1690. fcport->d_id.b.al_pa));
  1691. rval = qla2x00_start_sp(sp);
  1692. if (rval != QLA_SUCCESS) {
  1693. kfree(sp->ctx);
  1694. mempool_free(sp, ha->srb_mempool);
  1695. rval = -EIO;
  1696. goto done_unmap_sg;
  1697. }
  1698. return rval;
  1699. done_unmap_sg:
  1700. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1701. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1702. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1703. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1704. goto done_free_fcport;
  1705. done_free_fcport:
  1706. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  1707. kfree(fcport);
  1708. done:
  1709. return rval;
  1710. }
  1711. static int
  1712. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  1713. {
  1714. srb_t *sp;
  1715. struct Scsi_Host *host = bsg_job->shost;
  1716. scsi_qla_host_t *vha = shost_priv(host);
  1717. struct qla_hw_data *ha = vha->hw;
  1718. int rval = (DRIVER_ERROR << 16);
  1719. int req_sg_cnt, rsp_sg_cnt;
  1720. uint16_t loop_id;
  1721. struct fc_port *fcport;
  1722. char *type = "FC_BSG_HST_CT";
  1723. struct srb_bsg *ct;
  1724. /* pass through is supported only for ISP 4Gb or higher */
  1725. if (!IS_FWI2_CAPABLE(ha)) {
  1726. DEBUG2(qla_printk(KERN_INFO, ha,
  1727. "scsi(%ld):Firmware is not capable to support FC "
  1728. "CT pass thru\n", vha->host_no));
  1729. rval = -EPERM;
  1730. goto done;
  1731. }
  1732. req_sg_cnt =
  1733. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1734. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1735. if (!req_sg_cnt) {
  1736. rval = -ENOMEM;
  1737. goto done;
  1738. }
  1739. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1740. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1741. if (!rsp_sg_cnt) {
  1742. rval = -ENOMEM;
  1743. goto done;
  1744. }
  1745. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1746. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1747. {
  1748. DEBUG2(qla_printk(KERN_WARNING, ha,
  1749. "dma mapping resulted in different sg counts \
  1750. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1751. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1752. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1753. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1754. rval = -EAGAIN;
  1755. goto done_unmap_sg;
  1756. }
  1757. if (!vha->flags.online) {
  1758. DEBUG2(qla_printk(KERN_WARNING, ha,
  1759. "host not online\n"));
  1760. rval = -EIO;
  1761. goto done_unmap_sg;
  1762. }
  1763. loop_id =
  1764. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  1765. >> 24;
  1766. switch (loop_id) {
  1767. case 0xFC:
  1768. loop_id = cpu_to_le16(NPH_SNS);
  1769. break;
  1770. case 0xFA:
  1771. loop_id = vha->mgmt_svr_loop_id;
  1772. break;
  1773. default:
  1774. DEBUG2(qla_printk(KERN_INFO, ha,
  1775. "Unknown loop id: %x\n", loop_id));
  1776. rval = -EINVAL;
  1777. goto done_unmap_sg;
  1778. }
  1779. /* Allocate a dummy fcport structure, since functions preparing the
  1780. * IOCB and mailbox command retrieves port specific information
  1781. * from fcport structure. For Host based ELS commands there will be
  1782. * no fcport structure allocated
  1783. */
  1784. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1785. if (!fcport)
  1786. {
  1787. rval = -ENOMEM;
  1788. goto done_unmap_sg;
  1789. }
  1790. /* Initialize all required fields of fcport */
  1791. fcport->vha = vha;
  1792. fcport->vp_idx = vha->vp_idx;
  1793. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  1794. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  1795. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  1796. fcport->loop_id = loop_id;
  1797. /* Alloc SRB structure */
  1798. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1799. if (!sp) {
  1800. rval = -ENOMEM;
  1801. goto done_free_fcport;
  1802. }
  1803. ct = sp->ctx;
  1804. ct->ctx.type = SRB_CT_CMD;
  1805. ct->bsg_job = bsg_job;
  1806. DEBUG2(qla_printk(KERN_INFO, ha,
  1807. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1808. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1809. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  1810. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1811. fcport->d_id.b.al_pa));
  1812. rval = qla2x00_start_sp(sp);
  1813. if (rval != QLA_SUCCESS) {
  1814. kfree(sp->ctx);
  1815. mempool_free(sp, ha->srb_mempool);
  1816. rval = -EIO;
  1817. goto done_free_fcport;
  1818. }
  1819. return rval;
  1820. done_free_fcport:
  1821. kfree(fcport);
  1822. done_unmap_sg:
  1823. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1824. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1825. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1826. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1827. done:
  1828. return rval;
  1829. }
  1830. static int
  1831. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1832. {
  1833. struct Scsi_Host *host = bsg_job->shost;
  1834. scsi_qla_host_t *vha = shost_priv(host);
  1835. struct qla_hw_data *ha = vha->hw;
  1836. int rval;
  1837. uint8_t command_sent;
  1838. uint32_t vendor_cmd;
  1839. char *type;
  1840. struct msg_echo_lb elreq;
  1841. uint16_t response[MAILBOX_REGISTER_COUNT];
  1842. uint8_t* fw_sts_ptr;
  1843. uint8_t *req_data;
  1844. dma_addr_t req_data_dma;
  1845. uint32_t req_data_len;
  1846. uint8_t *rsp_data;
  1847. dma_addr_t rsp_data_dma;
  1848. uint32_t rsp_data_len;
  1849. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1850. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1851. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1852. rval = -EBUSY;
  1853. goto done;
  1854. }
  1855. if (!vha->flags.online) {
  1856. DEBUG2(qla_printk(KERN_WARNING, ha,
  1857. "host not online\n"));
  1858. rval = -EIO;
  1859. goto done;
  1860. }
  1861. elreq.req_sg_cnt =
  1862. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1863. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1864. if (!elreq.req_sg_cnt) {
  1865. rval = -ENOMEM;
  1866. goto done;
  1867. }
  1868. elreq.rsp_sg_cnt =
  1869. dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1870. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1871. if (!elreq.rsp_sg_cnt) {
  1872. rval = -ENOMEM;
  1873. goto done;
  1874. }
  1875. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1876. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1877. {
  1878. DEBUG2(printk(KERN_INFO
  1879. "dma mapping resulted in different sg counts \
  1880. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1881. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1882. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  1883. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  1884. rval = -EAGAIN;
  1885. goto done_unmap_sg;
  1886. }
  1887. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  1888. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  1889. &req_data_dma, GFP_KERNEL);
  1890. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  1891. &rsp_data_dma, GFP_KERNEL);
  1892. /* Copy the request buffer in req_data now */
  1893. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1894. bsg_job->request_payload.sg_cnt, req_data,
  1895. req_data_len);
  1896. elreq.send_dma = req_data_dma;
  1897. elreq.rcv_dma = rsp_data_dma;
  1898. elreq.transfer_size = req_data_len;
  1899. /* Vendor cmd : loopback or ECHO diagnostic
  1900. * Options:
  1901. * Loopback : Either internal or external loopback
  1902. * ECHO: ECHO ELS or Vendor specific FC4 link data
  1903. */
  1904. vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
  1905. elreq.options =
  1906. *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
  1907. + 1);
  1908. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1909. case QL_VND_LOOPBACK:
  1910. if (ha->current_topology != ISP_CFG_F) {
  1911. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  1912. DEBUG2(qla_printk(KERN_INFO, ha,
  1913. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1914. vha->host_no, type, vendor_cmd, elreq.options));
  1915. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  1916. rval = qla2x00_loopback_test(vha, &elreq, response);
  1917. if (IS_QLA81XX(ha)) {
  1918. if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
  1919. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  1920. "ISP\n", __func__, vha->host_no));
  1921. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1922. qla2xxx_wake_dpc(vha);
  1923. }
  1924. }
  1925. } else {
  1926. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  1927. DEBUG2(qla_printk(KERN_INFO, ha,
  1928. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1929. vha->host_no, type, vendor_cmd, elreq.options));
  1930. command_sent = INT_DEF_LB_ECHO_CMD;
  1931. rval = qla2x00_echo_test(vha, &elreq, response);
  1932. }
  1933. break;
  1934. case QLA84_RESET:
  1935. if (!IS_QLA84XX(vha->hw)) {
  1936. rval = -EINVAL;
  1937. DEBUG16(printk(
  1938. "%s(%ld): 8xxx exiting.\n",
  1939. __func__, vha->host_no));
  1940. return rval;
  1941. }
  1942. rval = qla84xx_reset(vha, &elreq, bsg_job);
  1943. break;
  1944. case QLA84_MGMT_CMD:
  1945. if (!IS_QLA84XX(vha->hw)) {
  1946. rval = -EINVAL;
  1947. DEBUG16(printk(
  1948. "%s(%ld): 8xxx exiting.\n",
  1949. __func__, vha->host_no));
  1950. return rval;
  1951. }
  1952. rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
  1953. break;
  1954. default:
  1955. rval = -ENOSYS;
  1956. }
  1957. if (rval != QLA_SUCCESS) {
  1958. DEBUG2(qla_printk(KERN_WARNING, ha,
  1959. "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
  1960. rval = 0;
  1961. bsg_job->reply->result = (DID_ERROR << 16);
  1962. bsg_job->reply->reply_payload_rcv_len = 0;
  1963. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1964. memcpy( fw_sts_ptr, response, sizeof(response));
  1965. fw_sts_ptr += sizeof(response);
  1966. *fw_sts_ptr = command_sent;
  1967. } else {
  1968. DEBUG2(qla_printk(KERN_WARNING, ha,
  1969. "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
  1970. rval = bsg_job->reply->result = 0;
  1971. bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
  1972. bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
  1973. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1974. memcpy(fw_sts_ptr, response, sizeof(response));
  1975. fw_sts_ptr += sizeof(response);
  1976. *fw_sts_ptr = command_sent;
  1977. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1978. bsg_job->reply_payload.sg_cnt, rsp_data,
  1979. rsp_data_len);
  1980. }
  1981. bsg_job->job_done(bsg_job);
  1982. done_unmap_sg:
  1983. if(req_data)
  1984. dma_free_coherent(&ha->pdev->dev, req_data_len,
  1985. req_data, req_data_dma);
  1986. dma_unmap_sg(&ha->pdev->dev,
  1987. bsg_job->request_payload.sg_list,
  1988. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1989. dma_unmap_sg(&ha->pdev->dev,
  1990. bsg_job->reply_payload.sg_list,
  1991. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1992. done:
  1993. return rval;
  1994. }
  1995. static int
  1996. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1997. {
  1998. int ret = -EINVAL;
  1999. switch (bsg_job->request->msgcode) {
  2000. case FC_BSG_RPT_ELS:
  2001. case FC_BSG_HST_ELS_NOLOGIN:
  2002. ret = qla2x00_process_els(bsg_job);
  2003. break;
  2004. case FC_BSG_HST_CT:
  2005. ret = qla2x00_process_ct(bsg_job);
  2006. break;
  2007. case FC_BSG_HST_VENDOR:
  2008. ret = qla2x00_process_vendor_specific(bsg_job);
  2009. break;
  2010. case FC_BSG_HST_ADD_RPORT:
  2011. case FC_BSG_HST_DEL_RPORT:
  2012. case FC_BSG_RPT_CT:
  2013. default:
  2014. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  2015. break;
  2016. }
  2017. return ret;
  2018. }
  2019. static int
  2020. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  2021. {
  2022. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  2023. struct qla_hw_data *ha = vha->hw;
  2024. srb_t *sp;
  2025. int cnt, que;
  2026. unsigned long flags;
  2027. struct req_que *req;
  2028. struct srb_bsg *sp_bsg;
  2029. /* find the bsg job from the active list of commands */
  2030. spin_lock_irqsave(&ha->hardware_lock, flags);
  2031. for (que = 0; que < ha->max_req_queues; que++) {
  2032. req = ha->req_q_map[que];
  2033. if (!req)
  2034. continue;
  2035. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
  2036. sp = req->outstanding_cmds[cnt];
  2037. if (sp) {
  2038. sp_bsg = (struct srb_bsg*)sp->ctx;
  2039. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  2040. (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
  2041. || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
  2042. (sp_bsg->bsg_job == bsg_job)) {
  2043. if (ha->isp_ops->abort_command(sp)) {
  2044. DEBUG2(qla_printk(KERN_INFO, ha,
  2045. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  2046. bsg_job->req->errors = bsg_job->reply->result = -EIO;
  2047. } else {
  2048. DEBUG2(qla_printk(KERN_INFO, ha,
  2049. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  2050. bsg_job->req->errors = bsg_job->reply->result = 0;
  2051. }
  2052. goto done;
  2053. }
  2054. }
  2055. }
  2056. }
  2057. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2058. DEBUG2(qla_printk(KERN_INFO, ha,
  2059. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  2060. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  2061. return 0;
  2062. done:
  2063. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  2064. kfree(sp->fcport);
  2065. kfree(sp->ctx);
  2066. mempool_free(sp, ha->srb_mempool);
  2067. return 0;
  2068. }
  2069. struct fc_function_template qla2xxx_transport_functions = {
  2070. .show_host_node_name = 1,
  2071. .show_host_port_name = 1,
  2072. .show_host_supported_classes = 1,
  2073. .show_host_supported_speeds = 1,
  2074. .get_host_port_id = qla2x00_get_host_port_id,
  2075. .show_host_port_id = 1,
  2076. .get_host_speed = qla2x00_get_host_speed,
  2077. .show_host_speed = 1,
  2078. .get_host_port_type = qla2x00_get_host_port_type,
  2079. .show_host_port_type = 1,
  2080. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2081. .show_host_symbolic_name = 1,
  2082. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2083. .show_host_system_hostname = 1,
  2084. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2085. .show_host_fabric_name = 1,
  2086. .get_host_port_state = qla2x00_get_host_port_state,
  2087. .show_host_port_state = 1,
  2088. .dd_fcrport_size = sizeof(struct fc_port *),
  2089. .show_rport_supported_classes = 1,
  2090. .get_starget_node_name = qla2x00_get_starget_node_name,
  2091. .show_starget_node_name = 1,
  2092. .get_starget_port_name = qla2x00_get_starget_port_name,
  2093. .show_starget_port_name = 1,
  2094. .get_starget_port_id = qla2x00_get_starget_port_id,
  2095. .show_starget_port_id = 1,
  2096. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2097. .show_rport_dev_loss_tmo = 1,
  2098. .issue_fc_host_lip = qla2x00_issue_lip,
  2099. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2100. .terminate_rport_io = qla2x00_terminate_rport_io,
  2101. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2102. .vport_create = qla24xx_vport_create,
  2103. .vport_disable = qla24xx_vport_disable,
  2104. .vport_delete = qla24xx_vport_delete,
  2105. .bsg_request = qla24xx_bsg_request,
  2106. .bsg_timeout = qla24xx_bsg_timeout,
  2107. };
  2108. struct fc_function_template qla2xxx_transport_vport_functions = {
  2109. .show_host_node_name = 1,
  2110. .show_host_port_name = 1,
  2111. .show_host_supported_classes = 1,
  2112. .get_host_port_id = qla2x00_get_host_port_id,
  2113. .show_host_port_id = 1,
  2114. .get_host_speed = qla2x00_get_host_speed,
  2115. .show_host_speed = 1,
  2116. .get_host_port_type = qla2x00_get_host_port_type,
  2117. .show_host_port_type = 1,
  2118. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2119. .show_host_symbolic_name = 1,
  2120. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2121. .show_host_system_hostname = 1,
  2122. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2123. .show_host_fabric_name = 1,
  2124. .get_host_port_state = qla2x00_get_host_port_state,
  2125. .show_host_port_state = 1,
  2126. .dd_fcrport_size = sizeof(struct fc_port *),
  2127. .show_rport_supported_classes = 1,
  2128. .get_starget_node_name = qla2x00_get_starget_node_name,
  2129. .show_starget_node_name = 1,
  2130. .get_starget_port_name = qla2x00_get_starget_port_name,
  2131. .show_starget_port_name = 1,
  2132. .get_starget_port_id = qla2x00_get_starget_port_id,
  2133. .show_starget_port_id = 1,
  2134. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2135. .show_rport_dev_loss_tmo = 1,
  2136. .issue_fc_host_lip = qla2x00_issue_lip,
  2137. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2138. .terminate_rport_io = qla2x00_terminate_rport_io,
  2139. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2140. .bsg_request = qla24xx_bsg_request,
  2141. .bsg_timeout = qla24xx_bsg_timeout,
  2142. };
  2143. void
  2144. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  2145. {
  2146. struct qla_hw_data *ha = vha->hw;
  2147. u32 speed = FC_PORTSPEED_UNKNOWN;
  2148. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  2149. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  2150. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  2151. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  2152. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  2153. if (IS_QLA81XX(ha))
  2154. speed = FC_PORTSPEED_10GBIT;
  2155. else if (IS_QLA25XX(ha))
  2156. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  2157. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2158. else if (IS_QLA24XX_TYPE(ha))
  2159. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  2160. FC_PORTSPEED_1GBIT;
  2161. else if (IS_QLA23XX(ha))
  2162. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2163. else
  2164. speed = FC_PORTSPEED_1GBIT;
  2165. fc_host_supported_speeds(vha->host) = speed;
  2166. }
  2167. static int
  2168. qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2169. {
  2170. int ret = 0;
  2171. int cmd;
  2172. uint16_t cmd_status;
  2173. DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2174. cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
  2175. == A84_RESET_FLAG_ENABLE_DIAG_FW ?
  2176. A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
  2177. ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
  2178. &cmd_status);
  2179. return ret;
  2180. }
  2181. static int
  2182. qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2183. {
  2184. struct access_chip_84xx *mn;
  2185. dma_addr_t mn_dma, mgmt_dma;
  2186. void *mgmt_b = NULL;
  2187. int ret = 0;
  2188. int rsp_hdr_len, len = 0;
  2189. struct qla84_msg_mgmt *ql84_mgmt;
  2190. ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
  2191. ql84_mgmt->cmd =
  2192. *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
  2193. ql84_mgmt->mgmtp.u.mem.start_addr =
  2194. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
  2195. ql84_mgmt->len =
  2196. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
  2197. ql84_mgmt->mgmtp.u.config.id =
  2198. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
  2199. ql84_mgmt->mgmtp.u.config.param0 =
  2200. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
  2201. ql84_mgmt->mgmtp.u.config.param1 =
  2202. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
  2203. ql84_mgmt->mgmtp.u.info.type =
  2204. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
  2205. ql84_mgmt->mgmtp.u.info.context =
  2206. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
  2207. rsp_hdr_len = bsg_job->request_payload.payload_len;
  2208. mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
  2209. if (mn == NULL) {
  2210. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  2211. "failed%lu\n", __func__, ha->host_no));
  2212. return -ENOMEM;
  2213. }
  2214. memset(mn, 0, sizeof (struct access_chip_84xx));
  2215. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  2216. mn->entry_count = 1;
  2217. switch (ql84_mgmt->cmd) {
  2218. case QLA84_MGMT_READ_MEM:
  2219. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  2220. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2221. break;
  2222. case QLA84_MGMT_WRITE_MEM:
  2223. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  2224. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2225. break;
  2226. case QLA84_MGMT_CHNG_CONFIG:
  2227. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  2228. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
  2229. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
  2230. mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
  2231. break;
  2232. case QLA84_MGMT_GET_INFO:
  2233. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  2234. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
  2235. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
  2236. break;
  2237. default:
  2238. ret = -EIO;
  2239. goto exit_mgmt0;
  2240. }
  2241. if ((len == ql84_mgmt->len) &&
  2242. ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
  2243. mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
  2244. &mgmt_dma, GFP_KERNEL);
  2245. if (mgmt_b == NULL) {
  2246. DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
  2247. "failed%lu\n", __func__, ha->host_no));
  2248. ret = -ENOMEM;
  2249. goto exit_mgmt0;
  2250. }
  2251. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
  2252. mn->dseg_count = cpu_to_le16(1);
  2253. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  2254. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  2255. mn->dseg_length = cpu_to_le32(len);
  2256. if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
  2257. memcpy(mgmt_b, ql84_mgmt->payload, len);
  2258. }
  2259. }
  2260. ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
  2261. if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
  2262. || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
  2263. if (ret != QLA_SUCCESS)
  2264. DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
  2265. __func__, ha->host_no));
  2266. } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
  2267. (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
  2268. }
  2269. if (mgmt_b)
  2270. dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
  2271. exit_mgmt0:
  2272. dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
  2273. return ret;
  2274. }