zfcp_fsf.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  22. "fsrth_1", NULL);
  23. }
  24. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  25. unsigned long timeout)
  26. {
  27. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  29. fsf_req->timer.expires = jiffies + timeout;
  30. add_timer(&fsf_req->timer);
  31. }
  32. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  33. {
  34. BUG_ON(!fsf_req->erp_action);
  35. fsf_req->timer.function = zfcp_erp_timeout_handler;
  36. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  37. fsf_req->timer.expires = jiffies + 30 * HZ;
  38. add_timer(&fsf_req->timer);
  39. }
  40. /* association between FSF command and FSF QTCB type */
  41. static u32 fsf_qtcb_type[] = {
  42. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  43. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  52. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  53. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = table >> 16;
  59. u16 rule = table & 0xffff;
  60. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  61. if (subtable && subtable < ARRAY_SIZE(act_type))
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied according to ACT rule type %s, "
  64. "rule %d\n", act_type[subtable], rule);
  65. }
  66. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  67. struct zfcp_port *port)
  68. {
  69. struct fsf_qtcb_header *header = &req->qtcb->header;
  70. dev_warn(&req->adapter->ccw_device->dev,
  71. "Access denied to port 0x%016Lx\n",
  72. (unsigned long long)port->wwpn);
  73. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  75. zfcp_erp_port_access_denied(port, "fspad_1", req);
  76. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  77. }
  78. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  79. struct zfcp_unit *unit)
  80. {
  81. struct fsf_qtcb_header *header = &req->qtcb->header;
  82. dev_warn(&req->adapter->ccw_device->dev,
  83. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  84. (unsigned long long)unit->fcp_lun,
  85. (unsigned long long)unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  94. "operational because of an unsupported FC class\n");
  95. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  96. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  97. }
  98. /**
  99. * zfcp_fsf_req_free - free memory used by fsf request
  100. * @fsf_req: pointer to struct zfcp_fsf_req
  101. */
  102. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  103. {
  104. if (likely(req->pool)) {
  105. if (likely(req->qtcb))
  106. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  107. mempool_free(req, req->pool);
  108. return;
  109. }
  110. if (likely(req->qtcb))
  111. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  112. kfree(req);
  113. }
  114. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  115. {
  116. unsigned long flags;
  117. struct fsf_status_read_buffer *sr_buf = req->data;
  118. struct zfcp_adapter *adapter = req->adapter;
  119. struct zfcp_port *port;
  120. int d_id = ntoh24(sr_buf->d_id);
  121. read_lock_irqsave(&adapter->port_list_lock, flags);
  122. list_for_each_entry(port, &adapter->port_list, list)
  123. if (port->d_id == d_id) {
  124. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  125. break;
  126. }
  127. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  128. }
  129. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  130. struct fsf_link_down_info *link_down)
  131. {
  132. struct zfcp_adapter *adapter = req->adapter;
  133. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  134. return;
  135. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  136. zfcp_scsi_schedule_rports_block(adapter);
  137. if (!link_down)
  138. goto out;
  139. switch (link_down->error_code) {
  140. case FSF_PSQ_LINK_NO_LIGHT:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "There is no light signal from the local "
  143. "fibre channel cable\n");
  144. break;
  145. case FSF_PSQ_LINK_WRAP_PLUG:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "There is a wrap plug instead of a fibre "
  148. "channel cable\n");
  149. break;
  150. case FSF_PSQ_LINK_NO_FCP:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The adjacent fibre channel node does not "
  153. "support FCP\n");
  154. break;
  155. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The FCP device is suspended because of a "
  158. "firmware update\n");
  159. break;
  160. case FSF_PSQ_LINK_INVALID_WWPN:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The FCP device detected a WWPN that is "
  163. "duplicate or not valid\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The fibre channel fabric does not support NPIV\n");
  168. break;
  169. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "The FCP adapter cannot support more NPIV ports\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent switch cannot support "
  176. "more NPIV ports\n");
  177. break;
  178. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP adapter could not log in to the "
  181. "fibre channel fabric\n");
  182. break;
  183. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The WWPN assignment file on the FCP adapter "
  186. "has been damaged\n");
  187. break;
  188. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The mode table on the FCP adapter "
  191. "has been damaged\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "All NPIV ports on the FCP adapter have "
  196. "been assigned\n");
  197. break;
  198. default:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The link between the FCP adapter and "
  201. "the FC fabric is down\n");
  202. }
  203. out:
  204. zfcp_erp_adapter_failed(adapter, id, req);
  205. }
  206. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  207. {
  208. struct fsf_status_read_buffer *sr_buf = req->data;
  209. struct fsf_link_down_info *ldi =
  210. (struct fsf_link_down_info *) &sr_buf->payload;
  211. switch (sr_buf->status_subtype) {
  212. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  213. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  214. break;
  215. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  216. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  217. break;
  218. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  219. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  220. };
  221. }
  222. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  223. {
  224. struct zfcp_adapter *adapter = req->adapter;
  225. struct fsf_status_read_buffer *sr_buf = req->data;
  226. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  227. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  228. mempool_free(sr_buf, adapter->pool.status_read_data);
  229. zfcp_fsf_req_free(req);
  230. return;
  231. }
  232. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  233. switch (sr_buf->status_type) {
  234. case FSF_STATUS_READ_PORT_CLOSED:
  235. zfcp_fsf_status_read_port_closed(req);
  236. break;
  237. case FSF_STATUS_READ_INCOMING_ELS:
  238. zfcp_fc_incoming_els(req);
  239. break;
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. break;
  242. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  243. dev_warn(&adapter->ccw_device->dev,
  244. "The error threshold for checksum statistics "
  245. "has been exceeded\n");
  246. zfcp_dbf_hba_berr(adapter->dbf, req);
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. zfcp_fsf_status_read_link_down(req);
  250. break;
  251. case FSF_STATUS_READ_LINK_UP:
  252. dev_info(&adapter->ccw_device->dev,
  253. "The local link has been restored\n");
  254. /* All ports should be marked as ready to run again */
  255. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  256. ZFCP_STATUS_COMMON_RUNNING,
  257. ZFCP_SET);
  258. zfcp_erp_adapter_reopen(adapter,
  259. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  260. ZFCP_STATUS_COMMON_ERP_FAILED,
  261. "fssrh_2", req);
  262. break;
  263. case FSF_STATUS_READ_NOTIFICATION_LOST:
  264. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  265. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  266. req);
  267. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  268. queue_work(adapter->work_queue, &adapter->scan_work);
  269. break;
  270. case FSF_STATUS_READ_CFDC_UPDATED:
  271. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  272. break;
  273. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  274. adapter->adapter_features = sr_buf->payload.word[0];
  275. break;
  276. }
  277. mempool_free(sr_buf, adapter->pool.status_read_data);
  278. zfcp_fsf_req_free(req);
  279. atomic_inc(&adapter->stat_miss);
  280. queue_work(adapter->work_queue, &adapter->stat_work);
  281. }
  282. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  283. {
  284. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  285. case FSF_SQ_FCP_RSP_AVAILABLE:
  286. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  287. case FSF_SQ_NO_RETRY_POSSIBLE:
  288. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  289. return;
  290. case FSF_SQ_COMMAND_ABORTED:
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. return;
  328. }
  329. switch (qtcb->prefix.prot_status) {
  330. case FSF_PROT_GOOD:
  331. case FSF_PROT_FSF_STATUS_PRESENTED:
  332. return;
  333. case FSF_PROT_QTCB_VERSION_ERROR:
  334. dev_err(&adapter->ccw_device->dev,
  335. "QTCB version 0x%x not supported by FCP adapter "
  336. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  337. psq->word[0], psq->word[1]);
  338. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  339. break;
  340. case FSF_PROT_ERROR_STATE:
  341. case FSF_PROT_SEQ_NUMB_ERROR:
  342. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  344. break;
  345. case FSF_PROT_UNSUPP_QTCB_TYPE:
  346. dev_err(&adapter->ccw_device->dev,
  347. "The QTCB type is not supported by the FCP adapter\n");
  348. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  349. break;
  350. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  351. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  352. &adapter->status);
  353. break;
  354. case FSF_PROT_DUPLICATE_REQUEST_ID:
  355. dev_err(&adapter->ccw_device->dev,
  356. "0x%Lx is an ambiguous request identifier\n",
  357. (unsigned long long)qtcb->bottom.support.req_handle);
  358. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  359. break;
  360. case FSF_PROT_LINK_DOWN:
  361. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  362. &psq->link_down_info);
  363. /* go through reopen to flush pending requests */
  364. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  365. break;
  366. case FSF_PROT_REEST_QUEUE:
  367. /* All ports should be marked as ready to run again */
  368. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  369. ZFCP_STATUS_COMMON_RUNNING,
  370. ZFCP_SET);
  371. zfcp_erp_adapter_reopen(adapter,
  372. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  373. ZFCP_STATUS_COMMON_ERP_FAILED,
  374. "fspse_8", req);
  375. break;
  376. default:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%x is not a valid transfer protocol status\n",
  379. qtcb->prefix.prot_status);
  380. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  381. }
  382. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. }
  384. /**
  385. * zfcp_fsf_req_complete - process completion of a FSF request
  386. * @fsf_req: The FSF request that has been completed.
  387. *
  388. * When a request has been completed either from the FCP adapter,
  389. * or it has been dismissed due to a queue shutdown, this function
  390. * is called to process the completion status and trigger further
  391. * events related to the FSF request.
  392. */
  393. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  394. {
  395. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  396. zfcp_fsf_status_read_handler(req);
  397. return;
  398. }
  399. del_timer(&req->timer);
  400. zfcp_fsf_protstatus_eval(req);
  401. zfcp_fsf_fsfstatus_eval(req);
  402. req->handler(req);
  403. if (req->erp_action)
  404. zfcp_erp_notify(req->erp_action, 0);
  405. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  406. zfcp_fsf_req_free(req);
  407. else
  408. complete(&req->completion);
  409. }
  410. /**
  411. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  412. * @adapter: pointer to struct zfcp_adapter
  413. *
  414. * Never ever call this without shutting down the adapter first.
  415. * Otherwise the adapter would continue using and corrupting s390 storage.
  416. * Included BUG_ON() call to ensure this is done.
  417. * ERP is supposed to be the only user of this function.
  418. */
  419. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  420. {
  421. struct zfcp_fsf_req *req, *tmp;
  422. LIST_HEAD(remove_queue);
  423. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  424. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  425. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  426. list_del(&req->list);
  427. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  428. zfcp_fsf_req_complete(req);
  429. }
  430. }
  431. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  432. {
  433. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  434. struct zfcp_adapter *adapter = req->adapter;
  435. struct Scsi_Host *shost = adapter->scsi_host;
  436. struct fc_els_flogi *nsp, *plogi;
  437. /* adjust pointers for missing command code */
  438. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  439. - sizeof(u32));
  440. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  441. - sizeof(u32));
  442. if (req->data)
  443. memcpy(req->data, bottom, sizeof(*bottom));
  444. fc_host_port_name(shost) = nsp->fl_wwpn;
  445. fc_host_node_name(shost) = nsp->fl_wwnn;
  446. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  447. fc_host_speed(shost) = bottom->fc_link_speed;
  448. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  449. adapter->hydra_version = bottom->adapter_type;
  450. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  451. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  452. (u16)FSF_STATUS_READS_RECOM);
  453. if (fc_host_permanent_port_name(shost) == -1)
  454. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  455. switch (bottom->fc_topology) {
  456. case FSF_TOPO_P2P:
  457. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  458. adapter->peer_wwpn = plogi->fl_wwpn;
  459. adapter->peer_wwnn = plogi->fl_wwnn;
  460. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  461. break;
  462. case FSF_TOPO_FABRIC:
  463. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  464. break;
  465. case FSF_TOPO_AL:
  466. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  467. /* fall through */
  468. default:
  469. dev_err(&adapter->ccw_device->dev,
  470. "Unknown or unsupported arbitrated loop "
  471. "fibre channel topology detected\n");
  472. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  473. return -EIO;
  474. }
  475. return 0;
  476. }
  477. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  478. {
  479. struct zfcp_adapter *adapter = req->adapter;
  480. struct fsf_qtcb *qtcb = req->qtcb;
  481. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  482. struct Scsi_Host *shost = adapter->scsi_host;
  483. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  484. return;
  485. adapter->fsf_lic_version = bottom->lic_version;
  486. adapter->adapter_features = bottom->adapter_features;
  487. adapter->connection_features = bottom->connection_features;
  488. adapter->peer_wwpn = 0;
  489. adapter->peer_wwnn = 0;
  490. adapter->peer_d_id = 0;
  491. switch (qtcb->header.fsf_status) {
  492. case FSF_GOOD:
  493. if (zfcp_fsf_exchange_config_evaluate(req))
  494. return;
  495. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  496. dev_err(&adapter->ccw_device->dev,
  497. "FCP adapter maximum QTCB size (%d bytes) "
  498. "is too small\n",
  499. bottom->max_qtcb_size);
  500. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  501. return;
  502. }
  503. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  504. &adapter->status);
  505. break;
  506. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  507. fc_host_node_name(shost) = 0;
  508. fc_host_port_name(shost) = 0;
  509. fc_host_port_id(shost) = 0;
  510. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  511. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  512. adapter->hydra_version = 0;
  513. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  514. &adapter->status);
  515. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  516. &qtcb->header.fsf_status_qual.link_down_info);
  517. break;
  518. default:
  519. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  520. return;
  521. }
  522. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  523. adapter->hardware_version = bottom->hardware_version;
  524. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. EBCASC(fc_host_serial_number(shost),
  527. min(FC_SERIAL_NUMBER_SIZE, 17));
  528. }
  529. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  530. dev_err(&adapter->ccw_device->dev,
  531. "The FCP adapter only supports newer "
  532. "control block versions\n");
  533. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  534. return;
  535. }
  536. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  537. dev_err(&adapter->ccw_device->dev,
  538. "The FCP adapter only supports older "
  539. "control block versions\n");
  540. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  541. }
  542. }
  543. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  544. {
  545. struct zfcp_adapter *adapter = req->adapter;
  546. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  547. struct Scsi_Host *shost = adapter->scsi_host;
  548. if (req->data)
  549. memcpy(req->data, bottom, sizeof(*bottom));
  550. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  551. fc_host_permanent_port_name(shost) = bottom->wwpn;
  552. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  553. } else
  554. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  555. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  556. fc_host_supported_speeds(shost) = bottom->supported_speed;
  557. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  558. FC_FC4_LIST_SIZE);
  559. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  560. FC_FC4_LIST_SIZE);
  561. }
  562. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  563. {
  564. struct fsf_qtcb *qtcb = req->qtcb;
  565. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  566. return;
  567. switch (qtcb->header.fsf_status) {
  568. case FSF_GOOD:
  569. zfcp_fsf_exchange_port_evaluate(req);
  570. break;
  571. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  574. &qtcb->header.fsf_status_qual.link_down_info);
  575. break;
  576. }
  577. }
  578. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  579. {
  580. struct zfcp_fsf_req *req;
  581. if (likely(pool))
  582. req = mempool_alloc(pool, GFP_ATOMIC);
  583. else
  584. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  585. if (unlikely(!req))
  586. return NULL;
  587. memset(req, 0, sizeof(*req));
  588. req->pool = pool;
  589. return req;
  590. }
  591. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  592. {
  593. struct fsf_qtcb *qtcb;
  594. if (likely(pool))
  595. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  596. else
  597. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  598. if (unlikely(!qtcb))
  599. return NULL;
  600. memset(qtcb, 0, sizeof(*qtcb));
  601. return qtcb;
  602. }
  603. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  604. u32 fsf_cmd, u32 sbtype,
  605. mempool_t *pool)
  606. {
  607. struct zfcp_adapter *adapter = qdio->adapter;
  608. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  609. if (unlikely(!req))
  610. return ERR_PTR(-ENOMEM);
  611. if (adapter->req_no == 0)
  612. adapter->req_no++;
  613. INIT_LIST_HEAD(&req->list);
  614. init_timer(&req->timer);
  615. init_completion(&req->completion);
  616. req->adapter = adapter;
  617. req->fsf_command = fsf_cmd;
  618. req->req_id = adapter->req_no;
  619. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  620. if (likely(pool))
  621. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  622. else
  623. req->qtcb = zfcp_qtcb_alloc(NULL);
  624. if (unlikely(!req->qtcb)) {
  625. zfcp_fsf_req_free(req);
  626. return ERR_PTR(-ENOMEM);
  627. }
  628. req->seq_no = adapter->fsf_req_seq_no;
  629. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  630. req->qtcb->prefix.req_id = req->req_id;
  631. req->qtcb->prefix.ulp_info = 26;
  632. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  633. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  634. req->qtcb->header.req_handle = req->req_id;
  635. req->qtcb->header.fsf_command = req->fsf_command;
  636. }
  637. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  638. req->qtcb, sizeof(struct fsf_qtcb));
  639. return req;
  640. }
  641. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  642. {
  643. struct zfcp_adapter *adapter = req->adapter;
  644. struct zfcp_qdio *qdio = adapter->qdio;
  645. int with_qtcb = (req->qtcb != NULL);
  646. int req_id = req->req_id;
  647. zfcp_reqlist_add(adapter->req_list, req);
  648. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  649. req->issued = get_clock();
  650. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  651. del_timer(&req->timer);
  652. /* lookup request again, list might have changed */
  653. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  654. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  655. return -EIO;
  656. }
  657. /* Don't increase for unsolicited status */
  658. if (with_qtcb)
  659. adapter->fsf_req_seq_no++;
  660. adapter->req_no++;
  661. return 0;
  662. }
  663. /**
  664. * zfcp_fsf_status_read - send status read request
  665. * @adapter: pointer to struct zfcp_adapter
  666. * @req_flags: request flags
  667. * Returns: 0 on success, ERROR otherwise
  668. */
  669. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  670. {
  671. struct zfcp_adapter *adapter = qdio->adapter;
  672. struct zfcp_fsf_req *req;
  673. struct fsf_status_read_buffer *sr_buf;
  674. int retval = -EIO;
  675. spin_lock_bh(&qdio->req_q_lock);
  676. if (zfcp_qdio_sbal_get(qdio))
  677. goto out;
  678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  679. adapter->pool.status_read_req);
  680. if (IS_ERR(req)) {
  681. retval = PTR_ERR(req);
  682. goto out;
  683. }
  684. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  685. if (!sr_buf) {
  686. retval = -ENOMEM;
  687. goto failed_buf;
  688. }
  689. memset(sr_buf, 0, sizeof(*sr_buf));
  690. req->data = sr_buf;
  691. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  692. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  693. retval = zfcp_fsf_req_send(req);
  694. if (retval)
  695. goto failed_req_send;
  696. goto out;
  697. failed_req_send:
  698. mempool_free(sr_buf, adapter->pool.status_read_data);
  699. failed_buf:
  700. zfcp_fsf_req_free(req);
  701. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  702. out:
  703. spin_unlock_bh(&qdio->req_q_lock);
  704. return retval;
  705. }
  706. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  707. {
  708. struct zfcp_unit *unit = req->data;
  709. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  710. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  711. return;
  712. switch (req->qtcb->header.fsf_status) {
  713. case FSF_PORT_HANDLE_NOT_VALID:
  714. if (fsq->word[0] == fsq->word[1]) {
  715. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  716. "fsafch1", req);
  717. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  718. }
  719. break;
  720. case FSF_LUN_HANDLE_NOT_VALID:
  721. if (fsq->word[0] == fsq->word[1]) {
  722. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  723. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  724. }
  725. break;
  726. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  727. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  728. break;
  729. case FSF_PORT_BOXED:
  730. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  731. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  732. break;
  733. case FSF_LUN_BOXED:
  734. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  735. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  736. break;
  737. case FSF_ADAPTER_STATUS_AVAILABLE:
  738. switch (fsq->word[0]) {
  739. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  740. zfcp_fc_test_link(unit->port);
  741. /* fall through */
  742. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  743. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  744. break;
  745. }
  746. break;
  747. case FSF_GOOD:
  748. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  749. break;
  750. }
  751. }
  752. /**
  753. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  754. * @old_req_id: unsigned long
  755. * @unit: pointer to struct zfcp_unit
  756. * Returns: pointer to struct zfcp_fsf_req
  757. */
  758. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  759. struct zfcp_unit *unit)
  760. {
  761. struct zfcp_fsf_req *req = NULL;
  762. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  763. spin_lock_bh(&qdio->req_q_lock);
  764. if (zfcp_qdio_sbal_get(qdio))
  765. goto out;
  766. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  767. SBAL_FLAGS0_TYPE_READ,
  768. qdio->adapter->pool.scsi_abort);
  769. if (IS_ERR(req)) {
  770. req = NULL;
  771. goto out;
  772. }
  773. if (unlikely(!(atomic_read(&unit->status) &
  774. ZFCP_STATUS_COMMON_UNBLOCKED)))
  775. goto out_error_free;
  776. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  777. req->data = unit;
  778. req->handler = zfcp_fsf_abort_fcp_command_handler;
  779. req->qtcb->header.lun_handle = unit->handle;
  780. req->qtcb->header.port_handle = unit->port->handle;
  781. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  782. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  783. if (!zfcp_fsf_req_send(req))
  784. goto out;
  785. out_error_free:
  786. zfcp_fsf_req_free(req);
  787. req = NULL;
  788. out:
  789. spin_unlock_bh(&qdio->req_q_lock);
  790. return req;
  791. }
  792. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  793. {
  794. struct zfcp_adapter *adapter = req->adapter;
  795. struct zfcp_fsf_ct_els *ct = req->data;
  796. struct fsf_qtcb_header *header = &req->qtcb->header;
  797. ct->status = -EINVAL;
  798. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  799. goto skip_fsfstatus;
  800. switch (header->fsf_status) {
  801. case FSF_GOOD:
  802. zfcp_dbf_san_ct_response(req);
  803. ct->status = 0;
  804. break;
  805. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  806. zfcp_fsf_class_not_supp(req);
  807. break;
  808. case FSF_ADAPTER_STATUS_AVAILABLE:
  809. switch (header->fsf_status_qual.word[0]){
  810. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  811. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  812. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  813. break;
  814. }
  815. break;
  816. case FSF_ACCESS_DENIED:
  817. break;
  818. case FSF_PORT_BOXED:
  819. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  820. break;
  821. case FSF_PORT_HANDLE_NOT_VALID:
  822. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  823. /* fall through */
  824. case FSF_GENERIC_COMMAND_REJECTED:
  825. case FSF_PAYLOAD_SIZE_MISMATCH:
  826. case FSF_REQUEST_SIZE_TOO_LARGE:
  827. case FSF_RESPONSE_SIZE_TOO_LARGE:
  828. case FSF_SBAL_MISMATCH:
  829. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  830. break;
  831. }
  832. skip_fsfstatus:
  833. if (ct->handler)
  834. ct->handler(ct->handler_data);
  835. }
  836. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  837. struct zfcp_qdio_req *q_req,
  838. struct scatterlist *sg_req,
  839. struct scatterlist *sg_resp)
  840. {
  841. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  842. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  843. zfcp_qdio_set_sbale_last(qdio, q_req);
  844. }
  845. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  846. struct scatterlist *sg_req,
  847. struct scatterlist *sg_resp)
  848. {
  849. struct zfcp_adapter *adapter = req->adapter;
  850. u32 feat = adapter->adapter_features;
  851. int bytes;
  852. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  853. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  854. !zfcp_qdio_sg_one_sbale(sg_resp))
  855. return -EOPNOTSUPP;
  856. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  857. sg_req, sg_resp);
  858. return 0;
  859. }
  860. /* use single, unchained SBAL if it can hold the request */
  861. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  862. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  863. sg_req, sg_resp);
  864. return 0;
  865. }
  866. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
  867. if (bytes <= 0)
  868. return -EIO;
  869. req->qtcb->bottom.support.req_buf_length = bytes;
  870. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  871. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  872. sg_resp);
  873. req->qtcb->bottom.support.resp_buf_length = bytes;
  874. if (bytes <= 0)
  875. return -EIO;
  876. return 0;
  877. }
  878. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  879. struct scatterlist *sg_req,
  880. struct scatterlist *sg_resp,
  881. unsigned int timeout)
  882. {
  883. int ret;
  884. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  885. if (ret)
  886. return ret;
  887. /* common settings for ct/gs and els requests */
  888. if (timeout > 255)
  889. timeout = 255; /* max value accepted by hardware */
  890. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  891. req->qtcb->bottom.support.timeout = timeout;
  892. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  893. return 0;
  894. }
  895. /**
  896. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  897. * @ct: pointer to struct zfcp_send_ct with data for request
  898. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  899. */
  900. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  901. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  902. unsigned int timeout)
  903. {
  904. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  905. struct zfcp_fsf_req *req;
  906. int ret = -EIO;
  907. spin_lock_bh(&qdio->req_q_lock);
  908. if (zfcp_qdio_sbal_get(qdio))
  909. goto out;
  910. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  911. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  912. if (IS_ERR(req)) {
  913. ret = PTR_ERR(req);
  914. goto out;
  915. }
  916. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  917. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  918. if (ret)
  919. goto failed_send;
  920. req->handler = zfcp_fsf_send_ct_handler;
  921. req->qtcb->header.port_handle = wka_port->handle;
  922. req->data = ct;
  923. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  924. ret = zfcp_fsf_req_send(req);
  925. if (ret)
  926. goto failed_send;
  927. goto out;
  928. failed_send:
  929. zfcp_fsf_req_free(req);
  930. out:
  931. spin_unlock_bh(&qdio->req_q_lock);
  932. return ret;
  933. }
  934. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  935. {
  936. struct zfcp_fsf_ct_els *send_els = req->data;
  937. struct zfcp_port *port = send_els->port;
  938. struct fsf_qtcb_header *header = &req->qtcb->header;
  939. send_els->status = -EINVAL;
  940. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  941. goto skip_fsfstatus;
  942. switch (header->fsf_status) {
  943. case FSF_GOOD:
  944. zfcp_dbf_san_els_response(req);
  945. send_els->status = 0;
  946. break;
  947. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  948. zfcp_fsf_class_not_supp(req);
  949. break;
  950. case FSF_ADAPTER_STATUS_AVAILABLE:
  951. switch (header->fsf_status_qual.word[0]){
  952. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  953. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  954. case FSF_SQ_RETRY_IF_POSSIBLE:
  955. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  956. break;
  957. }
  958. break;
  959. case FSF_ELS_COMMAND_REJECTED:
  960. case FSF_PAYLOAD_SIZE_MISMATCH:
  961. case FSF_REQUEST_SIZE_TOO_LARGE:
  962. case FSF_RESPONSE_SIZE_TOO_LARGE:
  963. break;
  964. case FSF_ACCESS_DENIED:
  965. if (port)
  966. zfcp_fsf_access_denied_port(req, port);
  967. break;
  968. case FSF_SBAL_MISMATCH:
  969. /* should never occure, avoided in zfcp_fsf_send_els */
  970. /* fall through */
  971. default:
  972. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  973. break;
  974. }
  975. skip_fsfstatus:
  976. if (send_els->handler)
  977. send_els->handler(send_els->handler_data);
  978. }
  979. /**
  980. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  981. * @els: pointer to struct zfcp_send_els with data for the command
  982. */
  983. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  984. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  985. {
  986. struct zfcp_fsf_req *req;
  987. struct zfcp_qdio *qdio = adapter->qdio;
  988. int ret = -EIO;
  989. spin_lock_bh(&qdio->req_q_lock);
  990. if (zfcp_qdio_sbal_get(qdio))
  991. goto out;
  992. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  993. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  994. if (IS_ERR(req)) {
  995. ret = PTR_ERR(req);
  996. goto out;
  997. }
  998. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  999. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1000. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1001. if (ret)
  1002. goto failed_send;
  1003. hton24(req->qtcb->bottom.support.d_id, d_id);
  1004. req->handler = zfcp_fsf_send_els_handler;
  1005. req->data = els;
  1006. zfcp_dbf_san_els_request(req);
  1007. ret = zfcp_fsf_req_send(req);
  1008. if (ret)
  1009. goto failed_send;
  1010. goto out;
  1011. failed_send:
  1012. zfcp_fsf_req_free(req);
  1013. out:
  1014. spin_unlock_bh(&qdio->req_q_lock);
  1015. return ret;
  1016. }
  1017. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1018. {
  1019. struct zfcp_fsf_req *req;
  1020. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1021. int retval = -EIO;
  1022. spin_lock_bh(&qdio->req_q_lock);
  1023. if (zfcp_qdio_sbal_get(qdio))
  1024. goto out;
  1025. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1026. SBAL_FLAGS0_TYPE_READ,
  1027. qdio->adapter->pool.erp_req);
  1028. if (IS_ERR(req)) {
  1029. retval = PTR_ERR(req);
  1030. goto out;
  1031. }
  1032. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1033. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1034. req->qtcb->bottom.config.feature_selection =
  1035. FSF_FEATURE_CFDC |
  1036. FSF_FEATURE_LUN_SHARING |
  1037. FSF_FEATURE_NOTIFICATION_LOST |
  1038. FSF_FEATURE_UPDATE_ALERT;
  1039. req->erp_action = erp_action;
  1040. req->handler = zfcp_fsf_exchange_config_data_handler;
  1041. erp_action->fsf_req_id = req->req_id;
  1042. zfcp_fsf_start_erp_timer(req);
  1043. retval = zfcp_fsf_req_send(req);
  1044. if (retval) {
  1045. zfcp_fsf_req_free(req);
  1046. erp_action->fsf_req_id = 0;
  1047. }
  1048. out:
  1049. spin_unlock_bh(&qdio->req_q_lock);
  1050. return retval;
  1051. }
  1052. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1053. struct fsf_qtcb_bottom_config *data)
  1054. {
  1055. struct zfcp_fsf_req *req = NULL;
  1056. int retval = -EIO;
  1057. spin_lock_bh(&qdio->req_q_lock);
  1058. if (zfcp_qdio_sbal_get(qdio))
  1059. goto out_unlock;
  1060. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1061. SBAL_FLAGS0_TYPE_READ, NULL);
  1062. if (IS_ERR(req)) {
  1063. retval = PTR_ERR(req);
  1064. goto out_unlock;
  1065. }
  1066. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1067. req->handler = zfcp_fsf_exchange_config_data_handler;
  1068. req->qtcb->bottom.config.feature_selection =
  1069. FSF_FEATURE_CFDC |
  1070. FSF_FEATURE_LUN_SHARING |
  1071. FSF_FEATURE_NOTIFICATION_LOST |
  1072. FSF_FEATURE_UPDATE_ALERT;
  1073. if (data)
  1074. req->data = data;
  1075. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1076. retval = zfcp_fsf_req_send(req);
  1077. spin_unlock_bh(&qdio->req_q_lock);
  1078. if (!retval)
  1079. wait_for_completion(&req->completion);
  1080. zfcp_fsf_req_free(req);
  1081. return retval;
  1082. out_unlock:
  1083. spin_unlock_bh(&qdio->req_q_lock);
  1084. return retval;
  1085. }
  1086. /**
  1087. * zfcp_fsf_exchange_port_data - request information about local port
  1088. * @erp_action: ERP action for the adapter for which port data is requested
  1089. * Returns: 0 on success, error otherwise
  1090. */
  1091. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1092. {
  1093. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1094. struct zfcp_fsf_req *req;
  1095. int retval = -EIO;
  1096. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1097. return -EOPNOTSUPP;
  1098. spin_lock_bh(&qdio->req_q_lock);
  1099. if (zfcp_qdio_sbal_get(qdio))
  1100. goto out;
  1101. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1102. SBAL_FLAGS0_TYPE_READ,
  1103. qdio->adapter->pool.erp_req);
  1104. if (IS_ERR(req)) {
  1105. retval = PTR_ERR(req);
  1106. goto out;
  1107. }
  1108. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1109. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1110. req->handler = zfcp_fsf_exchange_port_data_handler;
  1111. req->erp_action = erp_action;
  1112. erp_action->fsf_req_id = req->req_id;
  1113. zfcp_fsf_start_erp_timer(req);
  1114. retval = zfcp_fsf_req_send(req);
  1115. if (retval) {
  1116. zfcp_fsf_req_free(req);
  1117. erp_action->fsf_req_id = 0;
  1118. }
  1119. out:
  1120. spin_unlock_bh(&qdio->req_q_lock);
  1121. return retval;
  1122. }
  1123. /**
  1124. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1125. * @qdio: pointer to struct zfcp_qdio
  1126. * @data: pointer to struct fsf_qtcb_bottom_port
  1127. * Returns: 0 on success, error otherwise
  1128. */
  1129. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1130. struct fsf_qtcb_bottom_port *data)
  1131. {
  1132. struct zfcp_fsf_req *req = NULL;
  1133. int retval = -EIO;
  1134. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1135. return -EOPNOTSUPP;
  1136. spin_lock_bh(&qdio->req_q_lock);
  1137. if (zfcp_qdio_sbal_get(qdio))
  1138. goto out_unlock;
  1139. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1140. SBAL_FLAGS0_TYPE_READ, NULL);
  1141. if (IS_ERR(req)) {
  1142. retval = PTR_ERR(req);
  1143. goto out_unlock;
  1144. }
  1145. if (data)
  1146. req->data = data;
  1147. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1148. req->handler = zfcp_fsf_exchange_port_data_handler;
  1149. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1150. retval = zfcp_fsf_req_send(req);
  1151. spin_unlock_bh(&qdio->req_q_lock);
  1152. if (!retval)
  1153. wait_for_completion(&req->completion);
  1154. zfcp_fsf_req_free(req);
  1155. return retval;
  1156. out_unlock:
  1157. spin_unlock_bh(&qdio->req_q_lock);
  1158. return retval;
  1159. }
  1160. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1161. {
  1162. struct zfcp_port *port = req->data;
  1163. struct fsf_qtcb_header *header = &req->qtcb->header;
  1164. struct fc_els_flogi *plogi;
  1165. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1166. goto out;
  1167. switch (header->fsf_status) {
  1168. case FSF_PORT_ALREADY_OPEN:
  1169. break;
  1170. case FSF_ACCESS_DENIED:
  1171. zfcp_fsf_access_denied_port(req, port);
  1172. break;
  1173. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1174. dev_warn(&req->adapter->ccw_device->dev,
  1175. "Not enough FCP adapter resources to open "
  1176. "remote port 0x%016Lx\n",
  1177. (unsigned long long)port->wwpn);
  1178. zfcp_erp_port_failed(port, "fsoph_1", req);
  1179. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1180. break;
  1181. case FSF_ADAPTER_STATUS_AVAILABLE:
  1182. switch (header->fsf_status_qual.word[0]) {
  1183. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1184. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1185. case FSF_SQ_NO_RETRY_POSSIBLE:
  1186. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1187. break;
  1188. }
  1189. break;
  1190. case FSF_GOOD:
  1191. port->handle = header->port_handle;
  1192. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1193. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1194. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1195. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1196. &port->status);
  1197. /* check whether D_ID has changed during open */
  1198. /*
  1199. * FIXME: This check is not airtight, as the FCP channel does
  1200. * not monitor closures of target port connections caused on
  1201. * the remote side. Thus, they might miss out on invalidating
  1202. * locally cached WWPNs (and other N_Port parameters) of gone
  1203. * target ports. So, our heroic attempt to make things safe
  1204. * could be undermined by 'open port' response data tagged with
  1205. * obsolete WWPNs. Another reason to monitor potential
  1206. * connection closures ourself at least (by interpreting
  1207. * incoming ELS' and unsolicited status). It just crosses my
  1208. * mind that one should be able to cross-check by means of
  1209. * another GID_PN straight after a port has been opened.
  1210. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1211. */
  1212. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1213. if (req->qtcb->bottom.support.els1_length >=
  1214. FSF_PLOGI_MIN_LEN)
  1215. zfcp_fc_plogi_evaluate(port, plogi);
  1216. break;
  1217. case FSF_UNKNOWN_OP_SUBTYPE:
  1218. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1219. break;
  1220. }
  1221. out:
  1222. put_device(&port->dev);
  1223. }
  1224. /**
  1225. * zfcp_fsf_open_port - create and send open port request
  1226. * @erp_action: pointer to struct zfcp_erp_action
  1227. * Returns: 0 on success, error otherwise
  1228. */
  1229. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1230. {
  1231. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1232. struct zfcp_port *port = erp_action->port;
  1233. struct zfcp_fsf_req *req;
  1234. int retval = -EIO;
  1235. spin_lock_bh(&qdio->req_q_lock);
  1236. if (zfcp_qdio_sbal_get(qdio))
  1237. goto out;
  1238. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1239. SBAL_FLAGS0_TYPE_READ,
  1240. qdio->adapter->pool.erp_req);
  1241. if (IS_ERR(req)) {
  1242. retval = PTR_ERR(req);
  1243. goto out;
  1244. }
  1245. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1246. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1247. req->handler = zfcp_fsf_open_port_handler;
  1248. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1249. req->data = port;
  1250. req->erp_action = erp_action;
  1251. erp_action->fsf_req_id = req->req_id;
  1252. get_device(&port->dev);
  1253. zfcp_fsf_start_erp_timer(req);
  1254. retval = zfcp_fsf_req_send(req);
  1255. if (retval) {
  1256. zfcp_fsf_req_free(req);
  1257. erp_action->fsf_req_id = 0;
  1258. put_device(&port->dev);
  1259. }
  1260. out:
  1261. spin_unlock_bh(&qdio->req_q_lock);
  1262. return retval;
  1263. }
  1264. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1265. {
  1266. struct zfcp_port *port = req->data;
  1267. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1268. return;
  1269. switch (req->qtcb->header.fsf_status) {
  1270. case FSF_PORT_HANDLE_NOT_VALID:
  1271. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1272. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1273. break;
  1274. case FSF_ADAPTER_STATUS_AVAILABLE:
  1275. break;
  1276. case FSF_GOOD:
  1277. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1278. ZFCP_STATUS_COMMON_OPEN,
  1279. ZFCP_CLEAR);
  1280. break;
  1281. }
  1282. }
  1283. /**
  1284. * zfcp_fsf_close_port - create and send close port request
  1285. * @erp_action: pointer to struct zfcp_erp_action
  1286. * Returns: 0 on success, error otherwise
  1287. */
  1288. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1289. {
  1290. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1291. struct zfcp_fsf_req *req;
  1292. int retval = -EIO;
  1293. spin_lock_bh(&qdio->req_q_lock);
  1294. if (zfcp_qdio_sbal_get(qdio))
  1295. goto out;
  1296. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1297. SBAL_FLAGS0_TYPE_READ,
  1298. qdio->adapter->pool.erp_req);
  1299. if (IS_ERR(req)) {
  1300. retval = PTR_ERR(req);
  1301. goto out;
  1302. }
  1303. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1304. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1305. req->handler = zfcp_fsf_close_port_handler;
  1306. req->data = erp_action->port;
  1307. req->erp_action = erp_action;
  1308. req->qtcb->header.port_handle = erp_action->port->handle;
  1309. erp_action->fsf_req_id = req->req_id;
  1310. zfcp_fsf_start_erp_timer(req);
  1311. retval = zfcp_fsf_req_send(req);
  1312. if (retval) {
  1313. zfcp_fsf_req_free(req);
  1314. erp_action->fsf_req_id = 0;
  1315. }
  1316. out:
  1317. spin_unlock_bh(&qdio->req_q_lock);
  1318. return retval;
  1319. }
  1320. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1321. {
  1322. struct zfcp_fc_wka_port *wka_port = req->data;
  1323. struct fsf_qtcb_header *header = &req->qtcb->header;
  1324. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1325. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1326. goto out;
  1327. }
  1328. switch (header->fsf_status) {
  1329. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1330. dev_warn(&req->adapter->ccw_device->dev,
  1331. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1332. /* fall through */
  1333. case FSF_ADAPTER_STATUS_AVAILABLE:
  1334. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1335. /* fall through */
  1336. case FSF_ACCESS_DENIED:
  1337. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1338. break;
  1339. case FSF_GOOD:
  1340. wka_port->handle = header->port_handle;
  1341. /* fall through */
  1342. case FSF_PORT_ALREADY_OPEN:
  1343. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1344. }
  1345. out:
  1346. wake_up(&wka_port->completion_wq);
  1347. }
  1348. /**
  1349. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1350. * @wka_port: pointer to struct zfcp_fc_wka_port
  1351. * Returns: 0 on success, error otherwise
  1352. */
  1353. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1354. {
  1355. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1356. struct zfcp_fsf_req *req;
  1357. int retval = -EIO;
  1358. spin_lock_bh(&qdio->req_q_lock);
  1359. if (zfcp_qdio_sbal_get(qdio))
  1360. goto out;
  1361. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1362. SBAL_FLAGS0_TYPE_READ,
  1363. qdio->adapter->pool.erp_req);
  1364. if (unlikely(IS_ERR(req))) {
  1365. retval = PTR_ERR(req);
  1366. goto out;
  1367. }
  1368. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1369. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1370. req->handler = zfcp_fsf_open_wka_port_handler;
  1371. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1372. req->data = wka_port;
  1373. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1374. retval = zfcp_fsf_req_send(req);
  1375. if (retval)
  1376. zfcp_fsf_req_free(req);
  1377. out:
  1378. spin_unlock_bh(&qdio->req_q_lock);
  1379. return retval;
  1380. }
  1381. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1382. {
  1383. struct zfcp_fc_wka_port *wka_port = req->data;
  1384. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1385. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1386. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1387. }
  1388. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1389. wake_up(&wka_port->completion_wq);
  1390. }
  1391. /**
  1392. * zfcp_fsf_close_wka_port - create and send close wka port request
  1393. * @wka_port: WKA port to open
  1394. * Returns: 0 on success, error otherwise
  1395. */
  1396. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1397. {
  1398. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1399. struct zfcp_fsf_req *req;
  1400. int retval = -EIO;
  1401. spin_lock_bh(&qdio->req_q_lock);
  1402. if (zfcp_qdio_sbal_get(qdio))
  1403. goto out;
  1404. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1405. SBAL_FLAGS0_TYPE_READ,
  1406. qdio->adapter->pool.erp_req);
  1407. if (unlikely(IS_ERR(req))) {
  1408. retval = PTR_ERR(req);
  1409. goto out;
  1410. }
  1411. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1412. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1413. req->handler = zfcp_fsf_close_wka_port_handler;
  1414. req->data = wka_port;
  1415. req->qtcb->header.port_handle = wka_port->handle;
  1416. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1417. retval = zfcp_fsf_req_send(req);
  1418. if (retval)
  1419. zfcp_fsf_req_free(req);
  1420. out:
  1421. spin_unlock_bh(&qdio->req_q_lock);
  1422. return retval;
  1423. }
  1424. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1425. {
  1426. struct zfcp_port *port = req->data;
  1427. struct fsf_qtcb_header *header = &req->qtcb->header;
  1428. struct zfcp_unit *unit;
  1429. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1430. return;
  1431. switch (header->fsf_status) {
  1432. case FSF_PORT_HANDLE_NOT_VALID:
  1433. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1434. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1435. break;
  1436. case FSF_ACCESS_DENIED:
  1437. zfcp_fsf_access_denied_port(req, port);
  1438. break;
  1439. case FSF_PORT_BOXED:
  1440. /* can't use generic zfcp_erp_modify_port_status because
  1441. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1442. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1443. read_lock(&port->unit_list_lock);
  1444. list_for_each_entry(unit, &port->unit_list, list)
  1445. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1446. &unit->status);
  1447. read_unlock(&port->unit_list_lock);
  1448. zfcp_erp_port_boxed(port, "fscpph2", req);
  1449. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1450. break;
  1451. case FSF_ADAPTER_STATUS_AVAILABLE:
  1452. switch (header->fsf_status_qual.word[0]) {
  1453. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1454. /* fall through */
  1455. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1456. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1457. break;
  1458. }
  1459. break;
  1460. case FSF_GOOD:
  1461. /* can't use generic zfcp_erp_modify_port_status because
  1462. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1463. */
  1464. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1465. read_lock(&port->unit_list_lock);
  1466. list_for_each_entry(unit, &port->unit_list, list)
  1467. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1468. &unit->status);
  1469. read_unlock(&port->unit_list_lock);
  1470. break;
  1471. }
  1472. }
  1473. /**
  1474. * zfcp_fsf_close_physical_port - close physical port
  1475. * @erp_action: pointer to struct zfcp_erp_action
  1476. * Returns: 0 on success
  1477. */
  1478. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1479. {
  1480. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1481. struct zfcp_fsf_req *req;
  1482. int retval = -EIO;
  1483. spin_lock_bh(&qdio->req_q_lock);
  1484. if (zfcp_qdio_sbal_get(qdio))
  1485. goto out;
  1486. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1487. SBAL_FLAGS0_TYPE_READ,
  1488. qdio->adapter->pool.erp_req);
  1489. if (IS_ERR(req)) {
  1490. retval = PTR_ERR(req);
  1491. goto out;
  1492. }
  1493. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1494. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1495. req->data = erp_action->port;
  1496. req->qtcb->header.port_handle = erp_action->port->handle;
  1497. req->erp_action = erp_action;
  1498. req->handler = zfcp_fsf_close_physical_port_handler;
  1499. erp_action->fsf_req_id = req->req_id;
  1500. zfcp_fsf_start_erp_timer(req);
  1501. retval = zfcp_fsf_req_send(req);
  1502. if (retval) {
  1503. zfcp_fsf_req_free(req);
  1504. erp_action->fsf_req_id = 0;
  1505. }
  1506. out:
  1507. spin_unlock_bh(&qdio->req_q_lock);
  1508. return retval;
  1509. }
  1510. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1511. {
  1512. struct zfcp_adapter *adapter = req->adapter;
  1513. struct zfcp_unit *unit = req->data;
  1514. struct fsf_qtcb_header *header = &req->qtcb->header;
  1515. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1516. struct fsf_queue_designator *queue_designator =
  1517. &header->fsf_status_qual.fsf_queue_designator;
  1518. int exclusive, readwrite;
  1519. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1520. return;
  1521. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1522. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1523. ZFCP_STATUS_UNIT_SHARED |
  1524. ZFCP_STATUS_UNIT_READONLY,
  1525. &unit->status);
  1526. switch (header->fsf_status) {
  1527. case FSF_PORT_HANDLE_NOT_VALID:
  1528. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1529. /* fall through */
  1530. case FSF_LUN_ALREADY_OPEN:
  1531. break;
  1532. case FSF_ACCESS_DENIED:
  1533. zfcp_fsf_access_denied_unit(req, unit);
  1534. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1535. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1536. break;
  1537. case FSF_PORT_BOXED:
  1538. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1539. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1540. break;
  1541. case FSF_LUN_SHARING_VIOLATION:
  1542. if (header->fsf_status_qual.word[0])
  1543. dev_warn(&adapter->ccw_device->dev,
  1544. "LUN 0x%Lx on port 0x%Lx is already in "
  1545. "use by CSS%d, MIF Image ID %x\n",
  1546. (unsigned long long)unit->fcp_lun,
  1547. (unsigned long long)unit->port->wwpn,
  1548. queue_designator->cssid,
  1549. queue_designator->hla);
  1550. else
  1551. zfcp_act_eval_err(adapter,
  1552. header->fsf_status_qual.word[2]);
  1553. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1554. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1555. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1556. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1557. break;
  1558. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1559. dev_warn(&adapter->ccw_device->dev,
  1560. "No handle is available for LUN "
  1561. "0x%016Lx on port 0x%016Lx\n",
  1562. (unsigned long long)unit->fcp_lun,
  1563. (unsigned long long)unit->port->wwpn);
  1564. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1565. /* fall through */
  1566. case FSF_INVALID_COMMAND_OPTION:
  1567. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1568. break;
  1569. case FSF_ADAPTER_STATUS_AVAILABLE:
  1570. switch (header->fsf_status_qual.word[0]) {
  1571. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1572. zfcp_fc_test_link(unit->port);
  1573. /* fall through */
  1574. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1575. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1576. break;
  1577. }
  1578. break;
  1579. case FSF_GOOD:
  1580. unit->handle = header->lun_handle;
  1581. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1582. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1583. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1584. !zfcp_ccw_priv_sch(adapter)) {
  1585. exclusive = (bottom->lun_access_info &
  1586. FSF_UNIT_ACCESS_EXCLUSIVE);
  1587. readwrite = (bottom->lun_access_info &
  1588. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1589. if (!exclusive)
  1590. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1591. &unit->status);
  1592. if (!readwrite) {
  1593. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1594. &unit->status);
  1595. dev_info(&adapter->ccw_device->dev,
  1596. "SCSI device at LUN 0x%016Lx on port "
  1597. "0x%016Lx opened read-only\n",
  1598. (unsigned long long)unit->fcp_lun,
  1599. (unsigned long long)unit->port->wwpn);
  1600. }
  1601. if (exclusive && !readwrite) {
  1602. dev_err(&adapter->ccw_device->dev,
  1603. "Exclusive read-only access not "
  1604. "supported (unit 0x%016Lx, "
  1605. "port 0x%016Lx)\n",
  1606. (unsigned long long)unit->fcp_lun,
  1607. (unsigned long long)unit->port->wwpn);
  1608. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1609. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1610. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1611. } else if (!exclusive && readwrite) {
  1612. dev_err(&adapter->ccw_device->dev,
  1613. "Shared read-write access not "
  1614. "supported (unit 0x%016Lx, port "
  1615. "0x%016Lx)\n",
  1616. (unsigned long long)unit->fcp_lun,
  1617. (unsigned long long)unit->port->wwpn);
  1618. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1619. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1620. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1621. }
  1622. }
  1623. break;
  1624. }
  1625. }
  1626. /**
  1627. * zfcp_fsf_open_unit - open unit
  1628. * @erp_action: pointer to struct zfcp_erp_action
  1629. * Returns: 0 on success, error otherwise
  1630. */
  1631. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1632. {
  1633. struct zfcp_adapter *adapter = erp_action->adapter;
  1634. struct zfcp_qdio *qdio = adapter->qdio;
  1635. struct zfcp_fsf_req *req;
  1636. int retval = -EIO;
  1637. spin_lock_bh(&qdio->req_q_lock);
  1638. if (zfcp_qdio_sbal_get(qdio))
  1639. goto out;
  1640. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1641. SBAL_FLAGS0_TYPE_READ,
  1642. adapter->pool.erp_req);
  1643. if (IS_ERR(req)) {
  1644. retval = PTR_ERR(req);
  1645. goto out;
  1646. }
  1647. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1648. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1649. req->qtcb->header.port_handle = erp_action->port->handle;
  1650. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1651. req->handler = zfcp_fsf_open_unit_handler;
  1652. req->data = erp_action->unit;
  1653. req->erp_action = erp_action;
  1654. erp_action->fsf_req_id = req->req_id;
  1655. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1656. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1657. zfcp_fsf_start_erp_timer(req);
  1658. retval = zfcp_fsf_req_send(req);
  1659. if (retval) {
  1660. zfcp_fsf_req_free(req);
  1661. erp_action->fsf_req_id = 0;
  1662. }
  1663. out:
  1664. spin_unlock_bh(&qdio->req_q_lock);
  1665. return retval;
  1666. }
  1667. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1668. {
  1669. struct zfcp_unit *unit = req->data;
  1670. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1671. return;
  1672. switch (req->qtcb->header.fsf_status) {
  1673. case FSF_PORT_HANDLE_NOT_VALID:
  1674. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1675. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1676. break;
  1677. case FSF_LUN_HANDLE_NOT_VALID:
  1678. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1679. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1680. break;
  1681. case FSF_PORT_BOXED:
  1682. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1684. break;
  1685. case FSF_ADAPTER_STATUS_AVAILABLE:
  1686. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1687. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1688. zfcp_fc_test_link(unit->port);
  1689. /* fall through */
  1690. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1691. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1692. break;
  1693. }
  1694. break;
  1695. case FSF_GOOD:
  1696. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1697. break;
  1698. }
  1699. }
  1700. /**
  1701. * zfcp_fsf_close_unit - close zfcp unit
  1702. * @erp_action: pointer to struct zfcp_unit
  1703. * Returns: 0 on success, error otherwise
  1704. */
  1705. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1706. {
  1707. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1708. struct zfcp_fsf_req *req;
  1709. int retval = -EIO;
  1710. spin_lock_bh(&qdio->req_q_lock);
  1711. if (zfcp_qdio_sbal_get(qdio))
  1712. goto out;
  1713. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1714. SBAL_FLAGS0_TYPE_READ,
  1715. qdio->adapter->pool.erp_req);
  1716. if (IS_ERR(req)) {
  1717. retval = PTR_ERR(req);
  1718. goto out;
  1719. }
  1720. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1721. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1722. req->qtcb->header.port_handle = erp_action->port->handle;
  1723. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1724. req->handler = zfcp_fsf_close_unit_handler;
  1725. req->data = erp_action->unit;
  1726. req->erp_action = erp_action;
  1727. erp_action->fsf_req_id = req->req_id;
  1728. zfcp_fsf_start_erp_timer(req);
  1729. retval = zfcp_fsf_req_send(req);
  1730. if (retval) {
  1731. zfcp_fsf_req_free(req);
  1732. erp_action->fsf_req_id = 0;
  1733. }
  1734. out:
  1735. spin_unlock_bh(&qdio->req_q_lock);
  1736. return retval;
  1737. }
  1738. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1739. {
  1740. lat_rec->sum += lat;
  1741. lat_rec->min = min(lat_rec->min, lat);
  1742. lat_rec->max = max(lat_rec->max, lat);
  1743. }
  1744. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1745. {
  1746. struct fsf_qual_latency_info *lat_in;
  1747. struct latency_cont *lat = NULL;
  1748. struct zfcp_unit *unit = req->unit;
  1749. struct zfcp_blk_drv_data blktrc;
  1750. int ticks = req->adapter->timer_ticks;
  1751. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1752. blktrc.flags = 0;
  1753. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1754. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1755. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1756. blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
  1757. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1758. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1759. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1760. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1761. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1762. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1763. switch (req->qtcb->bottom.io.data_direction) {
  1764. case FSF_DATADIR_READ:
  1765. lat = &unit->latencies.read;
  1766. break;
  1767. case FSF_DATADIR_WRITE:
  1768. lat = &unit->latencies.write;
  1769. break;
  1770. case FSF_DATADIR_CMND:
  1771. lat = &unit->latencies.cmd;
  1772. break;
  1773. }
  1774. if (lat) {
  1775. spin_lock(&unit->latencies.lock);
  1776. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1777. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1778. lat->counter++;
  1779. spin_unlock(&unit->latencies.lock);
  1780. }
  1781. }
  1782. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1783. sizeof(blktrc));
  1784. }
  1785. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1786. {
  1787. struct scsi_cmnd *scpnt;
  1788. struct fcp_resp_with_ext *fcp_rsp;
  1789. unsigned long flags;
  1790. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1791. scpnt = req->data;
  1792. if (unlikely(!scpnt)) {
  1793. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1794. return;
  1795. }
  1796. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1797. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1798. goto skip_fsfstatus;
  1799. }
  1800. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1801. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1802. skip_fsfstatus:
  1803. zfcp_fsf_req_trace(req, scpnt);
  1804. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1805. scpnt->host_scribble = NULL;
  1806. (scpnt->scsi_done) (scpnt);
  1807. /*
  1808. * We must hold this lock until scsi_done has been called.
  1809. * Otherwise we may call scsi_done after abort regarding this
  1810. * command has completed.
  1811. * Note: scsi_done must not block!
  1812. */
  1813. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1814. }
  1815. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1816. {
  1817. struct fcp_resp_with_ext *fcp_rsp;
  1818. struct fcp_resp_rsp_info *rsp_info;
  1819. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1820. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1821. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1822. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1823. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1824. }
  1825. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1826. {
  1827. struct zfcp_unit *unit;
  1828. struct fsf_qtcb_header *header = &req->qtcb->header;
  1829. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1830. unit = req->data;
  1831. else
  1832. unit = req->unit;
  1833. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1834. goto skip_fsfstatus;
  1835. switch (header->fsf_status) {
  1836. case FSF_HANDLE_MISMATCH:
  1837. case FSF_PORT_HANDLE_NOT_VALID:
  1838. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1839. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1840. break;
  1841. case FSF_FCPLUN_NOT_VALID:
  1842. case FSF_LUN_HANDLE_NOT_VALID:
  1843. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1844. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1845. break;
  1846. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1847. zfcp_fsf_class_not_supp(req);
  1848. break;
  1849. case FSF_ACCESS_DENIED:
  1850. zfcp_fsf_access_denied_unit(req, unit);
  1851. break;
  1852. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1853. dev_err(&req->adapter->ccw_device->dev,
  1854. "Incorrect direction %d, unit 0x%016Lx on port "
  1855. "0x%016Lx closed\n",
  1856. req->qtcb->bottom.io.data_direction,
  1857. (unsigned long long)unit->fcp_lun,
  1858. (unsigned long long)unit->port->wwpn);
  1859. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1860. req);
  1861. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1862. break;
  1863. case FSF_CMND_LENGTH_NOT_VALID:
  1864. dev_err(&req->adapter->ccw_device->dev,
  1865. "Incorrect CDB length %d, unit 0x%016Lx on "
  1866. "port 0x%016Lx closed\n",
  1867. req->qtcb->bottom.io.fcp_cmnd_length,
  1868. (unsigned long long)unit->fcp_lun,
  1869. (unsigned long long)unit->port->wwpn);
  1870. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1871. req);
  1872. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1873. break;
  1874. case FSF_PORT_BOXED:
  1875. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1876. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1877. break;
  1878. case FSF_LUN_BOXED:
  1879. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1880. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1881. break;
  1882. case FSF_ADAPTER_STATUS_AVAILABLE:
  1883. if (header->fsf_status_qual.word[0] ==
  1884. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1885. zfcp_fc_test_link(unit->port);
  1886. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1887. break;
  1888. }
  1889. skip_fsfstatus:
  1890. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1891. zfcp_fsf_send_fcp_ctm_handler(req);
  1892. else {
  1893. zfcp_fsf_send_fcp_command_task_handler(req);
  1894. req->unit = NULL;
  1895. put_device(&unit->dev);
  1896. }
  1897. }
  1898. /**
  1899. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1900. * @unit: unit where command is sent to
  1901. * @scsi_cmnd: scsi command to be sent
  1902. */
  1903. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1904. struct scsi_cmnd *scsi_cmnd)
  1905. {
  1906. struct zfcp_fsf_req *req;
  1907. struct fcp_cmnd *fcp_cmnd;
  1908. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1909. int real_bytes, retval = -EIO;
  1910. struct zfcp_adapter *adapter = unit->port->adapter;
  1911. struct zfcp_qdio *qdio = adapter->qdio;
  1912. if (unlikely(!(atomic_read(&unit->status) &
  1913. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1914. return -EBUSY;
  1915. spin_lock(&qdio->req_q_lock);
  1916. if (atomic_read(&qdio->req_q.count) <= 0) {
  1917. atomic_inc(&qdio->req_q_full);
  1918. goto out;
  1919. }
  1920. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1921. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1922. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1923. sbtype, adapter->pool.scsi_req);
  1924. if (IS_ERR(req)) {
  1925. retval = PTR_ERR(req);
  1926. goto out;
  1927. }
  1928. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1929. req->unit = unit;
  1930. req->data = scsi_cmnd;
  1931. req->handler = zfcp_fsf_send_fcp_command_handler;
  1932. req->qtcb->header.lun_handle = unit->handle;
  1933. req->qtcb->header.port_handle = unit->port->handle;
  1934. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1935. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1936. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1937. /*
  1938. * set depending on data direction:
  1939. * data direction bits in SBALE (SB Type)
  1940. * data direction bits in QTCB
  1941. */
  1942. switch (scsi_cmnd->sc_data_direction) {
  1943. case DMA_NONE:
  1944. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1945. break;
  1946. case DMA_FROM_DEVICE:
  1947. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1948. break;
  1949. case DMA_TO_DEVICE:
  1950. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1951. break;
  1952. case DMA_BIDIRECTIONAL:
  1953. goto failed_scsi_cmnd;
  1954. }
  1955. get_device(&unit->dev);
  1956. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1957. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1958. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1959. scsi_sglist(scsi_cmnd));
  1960. if (unlikely(real_bytes < 0))
  1961. goto failed_scsi_cmnd;
  1962. retval = zfcp_fsf_req_send(req);
  1963. if (unlikely(retval))
  1964. goto failed_scsi_cmnd;
  1965. goto out;
  1966. failed_scsi_cmnd:
  1967. put_device(&unit->dev);
  1968. zfcp_fsf_req_free(req);
  1969. scsi_cmnd->host_scribble = NULL;
  1970. out:
  1971. spin_unlock(&qdio->req_q_lock);
  1972. return retval;
  1973. }
  1974. /**
  1975. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1976. * @unit: pointer to struct zfcp_unit
  1977. * @tm_flags: unsigned byte for task management flags
  1978. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1979. */
  1980. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  1981. {
  1982. struct zfcp_fsf_req *req = NULL;
  1983. struct fcp_cmnd *fcp_cmnd;
  1984. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  1985. if (unlikely(!(atomic_read(&unit->status) &
  1986. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1987. return NULL;
  1988. spin_lock_bh(&qdio->req_q_lock);
  1989. if (zfcp_qdio_sbal_get(qdio))
  1990. goto out;
  1991. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1992. SBAL_FLAGS0_TYPE_WRITE,
  1993. qdio->adapter->pool.scsi_req);
  1994. if (IS_ERR(req)) {
  1995. req = NULL;
  1996. goto out;
  1997. }
  1998. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  1999. req->data = unit;
  2000. req->handler = zfcp_fsf_send_fcp_command_handler;
  2001. req->qtcb->header.lun_handle = unit->handle;
  2002. req->qtcb->header.port_handle = unit->port->handle;
  2003. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2004. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2005. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2006. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2007. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2008. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2009. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2010. if (!zfcp_fsf_req_send(req))
  2011. goto out;
  2012. zfcp_fsf_req_free(req);
  2013. req = NULL;
  2014. out:
  2015. spin_unlock_bh(&qdio->req_q_lock);
  2016. return req;
  2017. }
  2018. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2019. {
  2020. }
  2021. /**
  2022. * zfcp_fsf_control_file - control file upload/download
  2023. * @adapter: pointer to struct zfcp_adapter
  2024. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2025. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2026. */
  2027. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2028. struct zfcp_fsf_cfdc *fsf_cfdc)
  2029. {
  2030. struct zfcp_qdio *qdio = adapter->qdio;
  2031. struct zfcp_fsf_req *req = NULL;
  2032. struct fsf_qtcb_bottom_support *bottom;
  2033. int direction, retval = -EIO, bytes;
  2034. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2035. return ERR_PTR(-EOPNOTSUPP);
  2036. switch (fsf_cfdc->command) {
  2037. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2038. direction = SBAL_FLAGS0_TYPE_WRITE;
  2039. break;
  2040. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2041. direction = SBAL_FLAGS0_TYPE_READ;
  2042. break;
  2043. default:
  2044. return ERR_PTR(-EINVAL);
  2045. }
  2046. spin_lock_bh(&qdio->req_q_lock);
  2047. if (zfcp_qdio_sbal_get(qdio))
  2048. goto out;
  2049. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2050. if (IS_ERR(req)) {
  2051. retval = -EPERM;
  2052. goto out;
  2053. }
  2054. req->handler = zfcp_fsf_control_file_handler;
  2055. bottom = &req->qtcb->bottom.support;
  2056. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2057. bottom->option = fsf_cfdc->option;
  2058. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2059. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2060. zfcp_fsf_req_free(req);
  2061. goto out;
  2062. }
  2063. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2064. retval = zfcp_fsf_req_send(req);
  2065. out:
  2066. spin_unlock_bh(&qdio->req_q_lock);
  2067. if (!retval) {
  2068. wait_for_completion(&req->completion);
  2069. return req;
  2070. }
  2071. return ERR_PTR(retval);
  2072. }
  2073. /**
  2074. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2075. * @adapter: pointer to struct zfcp_adapter
  2076. * @sbal_idx: response queue index of SBAL to be processed
  2077. */
  2078. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2079. {
  2080. struct zfcp_adapter *adapter = qdio->adapter;
  2081. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2082. struct qdio_buffer_element *sbale;
  2083. struct zfcp_fsf_req *fsf_req;
  2084. unsigned long req_id;
  2085. int idx;
  2086. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2087. sbale = &sbal->element[idx];
  2088. req_id = (unsigned long) sbale->addr;
  2089. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2090. if (!fsf_req)
  2091. /*
  2092. * Unknown request means that we have potentially memory
  2093. * corruption and must stop the machine immediately.
  2094. */
  2095. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2096. req_id, dev_name(&adapter->ccw_device->dev));
  2097. fsf_req->qdio_req.sbal_response = sbal_idx;
  2098. fsf_req->qdio_req.qdio_inb_usage =
  2099. atomic_read(&qdio->resp_q.count);
  2100. zfcp_fsf_req_complete(fsf_req);
  2101. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2102. break;
  2103. }
  2104. }