zfcp_fsf.c 70 KB

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